2016-04-05 5 views
0

Ich versuche, eine Art von Bildergalerie mit einem HorizontalScrollView erstellen. Ich möchte eine Taste vertikal zentriert haben, aber selbst wenn ich die gravity als center_vertical in meiner Taste angeben, gibt es keine Möglichkeit, es funktioniert, da es immer an der Spitze bleibt. Hier ist mein Layout:Android - Zentrierung Button in einem HorizontalScrollView

 <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> 

Vielen Dank im Voraus!

+2

Stellen Sie die Höhe Ihres linearen Layouts auf match_parent –

+0

Vielen Dank, mein Schlechter! – noloman

Antwort

0

Auf dem Linearlayout innerhalb des HorizontalScrollView verwenden

android:layout_gravity="center_vertical" 

statt

android:gravity="center_vertical" 
0

Ein Mock-up-Bildschirm wirklich um herauszufinden, würde helfen, was Sie genau wollen. Wie auch immer, von deinem Layout her könnte ich das verstehen, du musst einen Kameraknopf in die Mitte deines HorizontalScrollView setzen.

In diesem Fall Sie

<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

unter Ihrem horizontalen Scrollview mit einem RelativeLayout wie das Beispiel der Verpackung Bitte füge android:fillViewport="true" in Ihrer beide Scroll-Ansicht

0

das Linearlayout festgelegt in der HorizontalScrollView so denken könnten:

<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> 

das Ergebnis:

Button Centered Vertically

Übrigens: Sie können das Attribut android: layout_gravity = "center_vertical" in Ihrem Button loswerden.