2016-12-26 1 views
1

다음 활동이 있습니다.ScrollView가 작동하지 않을 때 다음 Android 활동을 스크롤 할 수있게 만드는 방법은 무엇입니까?

전체 RelativeLayoutScrollView으로 캡슐화하려고했습니다. 그러나 작동하지 않으며 마지막 2 개의 이미지 만 표시됩니다. 따라서 질문을 삭제하고 RelativeLayout을 게시했습니다. 도와주세요. 나는 스크린 중앙에 가상의 수직선과 수평선을 표시하는 2 개의 더미보기가 있으며, 모든 이미지는 그것들에 상대적으로 정렬되어있다.

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 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:id="@+id/content_front" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/colorWhite" 
     android:fillViewport="true" 
     android:gravity="center_vertical" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 
     tools:context=".FrontActivity" 
     tools:showIn="@layout/activity_front" 
     > 

     <View 
      android:id="@+id/dummy" 
      android:layout_width="1dp" 
      android:layout_height="match_parent" 
      android:layout_centerHorizontal="true" 
      android:layout_centerVertical="true" /> 

     <View 
      android:id="@+id/dummy2" 
      android:layout_width="match_parent" 
      android:layout_height="1dp" 
      android:layout_centerHorizontal="true" 
      android:layout_centerVertical="true" /> 

     <ImageView 
      android:id="@+id/all1" 
      android:layout_width="100dp" 
      android:layout_height="100dp" 
      android:layout_above="@+id/part2" 
      android:layout_margin="20dp" 
      android:layout_toLeftOf="@+id/dummy" 
      android:layout_toStartOf="@+id/dummy" 
      android:adjustViewBounds="false" 
      android:contentDescription="@string/app_name" 
      android:scaleType="fitCenter" 
      android:src="@mipmap/all" /> 

     <ImageView 
      android:id="@+id/part1" 
      android:layout_width="100dp" 
      android:layout_height="100dp" 
      android:layout_above="@+id/part3" 
      android:layout_margin="20dp" 
      android:layout_toEndOf="@+id/dummy" 
      android:layout_toRightOf="@+id/dummy" 
      android:adjustViewBounds="false" 
      android:contentDescription="@string/app_name" 
      android:scaleType="fitCenter" 
      android:src="@mipmap/part1" /> 

     <ImageView 
      android:id="@+id/part2" 
      android:layout_width="100dp" 
      android:layout_height="100dp" 
      android:layout_above="@+id/dummy2" 
      android:layout_marginBottom="0dp" 
      android:layout_marginLeft="20dp" 
      android:layout_marginRight="20dp" 
      android:layout_marginTop="20dp" 
      android:layout_toLeftOf="@+id/dummy" 
      android:layout_toStartOf="@+id/dummy" 
      android:adjustViewBounds="false" 
      android:contentDescription="@string/app_name" 
      android:scaleType="fitCenter" 
      android:src="@mipmap/part2" /> 

     <ImageView 
      android:id="@+id/part3" 
      android:layout_width="100dp" 
      android:layout_height="100dp" 
      android:layout_above="@+id/dummy2" 
      android:layout_marginBottom="0dp" 
      android:layout_marginLeft="20dp" 
      android:layout_marginRight="20dp" 
      android:layout_marginTop="20dp" 
      android:layout_toEndOf="@+id/dummy" 
      android:layout_toRightOf="@+id/dummy" 
      android:adjustViewBounds="false" 
      android:contentDescription="@string/app_name" 
      android:scaleType="fitCenter" 
      android:src="@mipmap/part3" /> 

     <ImageView 
      android:id="@+id/part4" 
      android:layout_width="100dp" 
      android:layout_height="100dp" 
      android:layout_below="@+id/dummy2" 
      android:layout_marginEnd="20dp" 
      android:layout_marginRight="20dp" 
      android:layout_marginTop="40dp" 
      android:layout_toLeftOf="@+id/dummy" 
      android:layout_toStartOf="@+id/dummy" 
      android:adjustViewBounds="false" 
      android:contentDescription="@string/app_name" 
      android:scaleType="fitCenter" 
      android:src="@mipmap/part4" /> 

     <ImageView 
      android:id="@+id/part5" 
      android:layout_width="100dp" 
      android:layout_height="100dp" 
      android:layout_below="@+id/dummy2" 
      android:layout_marginLeft="20dp" 
      android:layout_marginStart="20dp" 
      android:layout_marginTop="40dp" 
      android:layout_toEndOf="@+id/dummy" 
      android:layout_toRightOf="@+id/dummy" 
      android:adjustViewBounds="false" 
      android:contentDescription="@string/app_name" 
      android:scaleType="fitCenter" 
      android:src="@mipmap/part5" /> 
    </RelativeLayout> 

더 효율적인 방법에 대한 정보는 감사하겠습니다. 감사합니다.

답변

0

첫 번째 팁 : 레이아웃에 공백 만있는 더미보기를 원할 때마다 Space보기를 사용하십시오.

두 번째 팁 : if you're supporting API 17 and aboveStartEnd 예선,하지에 대한 지원을 포함 (다만, 귀하의 minSdk에 따라) LeftRight을.


는 가짜 앵커 뷰를 사용하지 않고 TableLayout 또는 GridLayout 중 하나를 함께 수행 할 수 있습니다 무슨 일을하는지, 말했다. RelativeLayout을 사용하여 [0,0], [1,0]에 대한 [0,1]의 위치를 ​​[0,0], [1,1]에 따라 [1,0 ] 및 [0,1] 등등.

/당신은 완전히 당신의 요구 사항을 지정하지 않았다, 그래서 다른 구성에 적응하기 때문에 코드의 단순성과 유연성의 GridLayout를 사용하도록 자유를 가지고 있습니다 미래에 필요 는 (나는 또한 의심은 덜 비싼 것입니다 다른보기와 관련하여 위치를 정렬하는 것보다는 자신을 확인해야합니다. 어쨌든 minSdk를 17로 설정 했으므로 여기서 LeftRight 한정자는 포함하지 않습니다.

<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingStart="@dimen/activity_horizontal_margin" 
    android:paddingEnd="@dimen/activity_horizontal_margin" 
    android:columnCount="2" 
    android:layout_gravity="center_horizontal"> 
    <!-- Set columnCount according to your needs. --> 

    <ImageView 
     android:id="@+id/image_1" 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     android:adjustViewBounds="false" 
     android:layout_margin="20dp" 
     android:contentDescription="@string/app_name" 
     android:scaleType="fitCenter" 
     android:src="@mipmap/icon_1" /> 

    <ImageView 
     android:id="@+id/image_2" 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     android:adjustViewBounds="false" 
     android:layout_margin="20dp" 
     android:contentDescription="@string/app_name" 
     android:scaleType="fitCenter" 
     android:src="@mipmap/icon_2" /> 

<!-- Rinse and repeat. --> 

</GridLayout> 
관련 문제