2017-03-05 1 views
0

4 개의 이미지 버튼이 있으며 나중에 더 추가합니다. 나는 그들을 하나씩 추가하고 각각 하나는 이전의 것 아래에 놓고 싶습니다. 따라서 ScrollView을 만들었으므로 모든 버튼을 볼 수 있도록 스크롤 할 수 있습니다. 하지만 ScrollView을 추가 한 후에는 다른 요소를 이동할 수 없습니다. 레이아웃 아래Android 이미지 버튼을 하나씩 정렬하고 스크롤 가능

<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

android:layout_height="wrap_content"을 변경하는있는 LinearLayout을 사용하고 여기에

내 코드입니다 'android : gravity = "center"'여전히 – Zoe

답변

1

시도 :

android:fillViewport="true"을 추가하고 서로 후 정렬하는 경우 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

과 동일하고 겹치고 있습니다. – androidnewbie

+0

고마워요. w! – androidnewbie

+0

안녕하세요,하지만 마지막 버튼을 완전히 표시 할 수 없으므로 고칠 수 있으면 너무 상처가 있습니다. – androidnewbie

관련 문제