2017-11-16 3 views
0

**이 ScrollView 레이아웃 또는 LinearLayout 부모는 쓸모가 없습니다. 배경 속성을 다른보기로 옮깁니다. 형제가 없거나, 스크롤 뷰 또는 루트 레이아웃이 아니며 배경이없는 자식이있는 레이아웃을 제거하고 자식을 부모로 직접 이동시켜 더 평평하게 만들 수 있습니다 효율적인 레이아웃 계층. **불필요한 부모 레이아웃

`

<LinearLayout 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="match_parent" 
android:orientation="vertical" 

android:padding="10dp" 
android:background="#504b4b" 
tools:context="com.example.sompod.imageview.MainActivity"> 

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:visibility="visible" 
    > 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_gravity="center" 
     > 

     <ImageView 
      android:id="@+id/p1" 
      android:layout_width="260dp" 
      android:layout_height="260dp" 

      android:layout_marginLeft="25dp" 
      android:layout_marginStart="25dp" 
      android:contentDescription="@null" 
      android:rotation="270" 


      android:scaleType="fitXY" 
      android:src="@drawable/img_5116" 
      /> 

     <ImageView 
      android:id="@+id/p2" 
      android:layout_width="300dp" 
      android:layout_height="200dp" 
      android:layout_marginLeft="15dp" 
      android:layout_marginStart="15dp" 
      android:layout_marginTop="25dp" 
      android:contentDescription="@null" 
      android:scaleType="fitXY" 
      android:src="@drawable/bdboss" /> 

     <ImageView 
      android:id="@+id/p3" 
      android:layout_width="292dp" 
      android:layout_height="335dp" 
      android:layout_marginLeft="20dp" 
      android:layout_marginStart="20dp" 
      android:layout_marginTop="30dp" 
      android:contentDescription="@null" 
      android:rotation="270" 
      android:scaleType="fitXY" 
      android:src="@drawable/img_5123" /> 


     <ImageView 
      android:id="@+id/p4" 
      android:layout_width="225dp" 
      android:layout_height="279dp" 
      android:layout_marginLeft="25dp" 
      android:layout_marginStart="25dp" 
      android:layout_marginTop="15dp" 
      android:contentDescription="@null" 
      android:scaleType="fitXY" 
      android:src="@drawable/bestone1" /> 


    </LinearLayout> 

</ScrollView> 


</LinearLayout> 

`

+1

학부모 LL은 필요 없습니다. 이를 제거하고 ScrollView를 루트 레이아웃으로 만듭니다. – codeMagic

답변

0

부모 LinearLayout 쓸모가 - 값이 추가되지 않습니다. 이런 식으로 간단한 방법으로 동일하게 적용 할 수 있습니다.

<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="match_parent" 
android:background="#504b4b" 
tools:context="com.example.sompod.imageview.MainActivity"> 

    <LinearLayout 
     android:clipToPadding="false" 
     android:padding="10dp" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_gravity="center" 
     > 

     <ImageView 
      android:id="@+id/p1" 
      android:layout_width="260dp" 
      android:layout_height="260dp" 

      android:layout_marginLeft="25dp" 
      android:layout_marginStart="25dp" 
      android:contentDescription="@null" 
      android:rotation="270" 


      android:scaleType="fitXY" 
      android:src="@drawable/img_5116" 
      /> 

     <ImageView 
      android:id="@+id/p2" 
      android:layout_width="300dp" 
      android:layout_height="200dp" 
      android:layout_marginLeft="15dp" 
      android:layout_marginStart="15dp" 
      android:layout_marginTop="25dp" 
      android:contentDescription="@null" 
      android:scaleType="fitXY" 
      android:src="@drawable/bdboss" /> 

     <ImageView 
      android:id="@+id/p3" 
      android:layout_width="292dp" 
      android:layout_height="335dp" 
      android:layout_marginLeft="20dp" 
      android:layout_marginStart="20dp" 
      android:layout_marginTop="30dp" 
      android:contentDescription="@null" 
      android:rotation="270" 
      android:scaleType="fitXY" 
      android:src="@drawable/img_5123" /> 


     <ImageView 
      android:id="@+id/p4" 
      android:layout_width="225dp" 
      android:layout_height="279dp" 
      android:layout_marginLeft="25dp" 
      android:layout_marginStart="25dp" 
      android:layout_marginTop="15dp" 
      android:contentDescription="@null" 
      android:scaleType="fitXY" 
      android:src="@drawable/bestone1" /> 

    </LinearLayout> 

    </ScrollView> 
+2

좋은 답변에는 * 당신이 변경 한 사항과 * 어떻게 * 문제를 해결할 지에 대한 설명이 있어야합니다. – codeMagic