2016-04-05 19 views
0

HorizontalScrollViewを使用して画像ギャラリーの種類を作成しようとしています。 私はボタンを垂直にセンタリングしたいと思いますが、gravityを私のボタンにcenter_verticalと指定しても、常に上にくっつくので、機能させる方法はありません。事前にHorizo​​ntalScrollViewの中のAndroidのセンタリングボタン

 <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:animateLayoutChanges="true"> 

     <LinearLayout 
      android:id="@+id/container_layout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 

      <HorizontalScrollView 
       android:id="@+id/horizontal_scroll_view" 
       android:layout_width="match_parent" 
       android:layout_height="@dimen/cameraPlaceholderHeight"> 

       <LinearLayout 
        android:id="@+id/horizontal_scroll_view_container" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:background="@color/greyBackgroundColor" 
        android:gravity="start|center_vertical" 
        android:orientation="horizontal"> 

        <Button 
         android:id="@+id/camera_button" 
         android:layout_width="@dimen/take_picture_size" 
         android:layout_height="@dimen/take_picture_size" 
         android:layout_gravity="center_vertical" 
         android:background="@drawable/take_picture_rounded_button" 
         android:gravity="center_vertical" 
         android:src="@drawable/syi_camera_active"/> 
       </LinearLayout> 
      </HorizontalScrollView> 

ありがとう: はここに私のレイアウトです! Horizo​​ntalScrollView中にあなたのLinearLayoutで

+2

あなたの線形レイアウトの高さをmatch_parentに設定してください –

+0

ありがとう、私の悪い! – noloman

答えて

0

、代わりに

android:gravity="center_vertical" 
0

android:layout_gravity="center_vertical" 

モックアップ画面を使用するには、本当にあなたが正確に何をしたい見つけるために役立つだろう。とにかく、あなたのレイアウトからわかったことは、HorizontalScrollViewの中心にカメラのボタンを置く必要があることです。あなたは

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <HorizontalScrollView 
     android:id="@+id/horizontal_scroll_view" 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/activity_horizontal_margin"> 

     <!-- Other items here --> 
    </HorizontalScrollView> 

    <Button 
     android:id="@+id/camera_button" 
     android:layout_width="@dimen/activity_horizontal_margin" 
     android:layout_height="@dimen/activity_horizontal_margin" 
     android:layout_centerInParent="true" 
     android:background="@drawable/com_facebook_button_blue" 
     android:gravity="center_vertical" 
     android:src="@drawable/com_facebook_button_blue" /> 
</RelativeLayout> 
0

以下の例のようにRelativeLayoutであなたの横scrollviewをラップと思うかもしれませんその場合

あなたの両方のスクロールビューに

0

android:fillViewport="true"を追加してくださいは、そのようなHorizo​​ntalScrollViewの内側のLinearLayoutを設定します。

<HorizontalScrollView 
    android:id="@+id/horizontal_scroll_view" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:id="@+id/horizontal_scroll_view_container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:gravity="start|center_vertical" 
     android:orientation="horizontal"> 

     <Button 
      android:text="Button" 
      android:id="@+id/camera_button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="center_vertical"/> 
    </LinearLayout> 
</HorizontalScrollView> 

結果:

Button Centered Vertically

ところで、ボタンのアンドロイド:layout_gravity = "center_vertical"属性を取り除くことができます。

関連する問題