2017-03-05 8 views
0

Ich habe 4 Bild-Tasten, und später mehr hinzufügen. Ich möchte sie einzeln hinzufügen und jeder ist unter dem vorherigen. Daher habe ich ein ScrollView erstellt, so dass es scrollbar ist, alle Schaltflächen anzuzeigen. Aber nachdem ich die ScrollView hinzugefügt habe, kann ich andere Elemente nicht verschieben.Android Bild ausrichten Taste eins nach dem anderen und scrollbar

Hier ist mein Codes:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 

<RelativeLayout 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context="com.exampl.mygames.MainActivity$PlaceholderFragment"> 


<ImageButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    app:srcCompat="@drawable/btntower" 
    android:id="@+id/imageButton" 
    android:layout_alignParentTop="true" 
    android:scaleType="fitXY" 
    android:layout_centerHorizontal="true" 
    android:adjustViewBounds="true" 
    android:cropToPadding="false"/> 

<ImageButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    app:srcCompat="@drawable/btntower" 
    android:id="@+id/imageButton2" 
    android:layout_alignBottom="@+id/imageButton" 
    android:scaleType="fitXY" 
    android:layout_marginTop="20dip" 
    android:layout_centerHorizontal="true" 
    android:adjustViewBounds="true" 
    android:cropToPadding="false"/> 

<ImageButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    app:srcCompat="@drawable/btntower" 
    android:id="@+id/imageButton3" 
    android:layout_alignParentTop="true" 
    android:scaleType="fitXY" 
    android:layout_centerHorizontal="true" 
    android:adjustViewBounds="true" 
    android:cropToPadding="false"/> 

<ImageButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    app:srcCompat="@drawable/btntower" 
    android:id="@+id/imageButton4" 
    android:layout_alignParentTop="true" 
    android:scaleType="fitXY" 
    android:layout_centerHorizontal="true" 
    android:adjustViewBounds="true" 
    android:cropToPadding="false"/> 
</RelativeLayout> 
</ScrollView> 
+0

ändern, wenn sie hintereinander auszurichten, verwenden Sie ein Linearlayout und 'android: gravity =" center "' auf den imageButtons – Zoe

Antwort

1

Versuch unter Layout:

android:fillViewport="true" hinzufügen und android:layout_height="wrap_content" in scrollview

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:fillViewport="true"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin" 
     tools:context="com.exampl.mygames.MainActivity$PlaceholderFragment"> 


     <ImageButton 
      android:id="@+id/imageButton" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:layout_centerHorizontal="true" 
      android:adjustViewBounds="true" 
      android:cropToPadding="false" 
      android:scaleType="fitXY" 
      android:src="@mipmap/ic_launcher" /> 

     <ImageButton 
      android:id="@+id/imageButton2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/imageButton" 
      android:layout_centerHorizontal="true" 
      android:adjustViewBounds="true" 
      android:cropToPadding="false" 
      android:scaleType="fitXY" 
      android:src="@mipmap/ic_launcher" /> 

     <ImageButton 
      android:id="@+id/imageButton3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/imageButton2" 
      android:layout_centerHorizontal="true" 
      android:adjustViewBounds="true" 
      android:cropToPadding="false" 
      android:scaleType="fitXY" 
      android:src="@mipmap/ic_launcher" /> 

     <ImageButton 
      android:id="@+id/imageButton4" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/imageButton3" 
      android:layout_centerHorizontal="true" 
      android:adjustViewBounds="true" 
      android:cropToPadding="false" 
      android:scaleType="fitXY" 
      android:src="@mipmap/ic_launcher" /> 
    </RelativeLayout> 
</ScrollView> 
+0

immer noch die gleichen, sie sind überlappend – androidnewbie

+0

Vielen Dank, es funktioniert nicht w! – androidnewbie

+0

Hallo Sir, aber der letzte Knopf kann nicht komplett gezeigt werden, also habe ich Wunde, wenn Sie es auch bitte reparieren könnten? – androidnewbie

Verwandte Themen