2014-04-30 4 views
0

레이아웃을 작성하려고합니다. 코드는 다음과 같습니다. 레이아웃에 적절한 무게를 추가 할 수 없습니다. 아래 코드는 가중치가있는 레이아웃을 만들지 않습니다. 가중치가 추가되거나 추가되지 않는 레이아웃은 동일합니다. 제대로 설명하지 않았다면 용서해주십시오. 나는 완전히 프로그래밍에 익숙하지 않다.android : weightSum을 (를) 사용할 수 없습니다.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:weightSum="100" > 

<ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="30" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="TextView" /> 

     <EditText 
      android:id="@+id/editText1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:ems="10" > 
     </EditText> 

     <TextView 
      android:id="@+id/textView2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="TextView" /> 

     <EditText 
      android:id="@+id/editText2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:ems="10" /> 

     <TextView 
      android:id="@+id/textView3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="TextView" /> 

     <EditText 
      android:id="@+id/editText3" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:ems="10" /> 

     <TextView 
      android:id="@+id/textView4" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="TextView" /> 

     <EditText 
      android:id="@+id/editText4" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:ems="10" /> 

     <TextView 
      android:id="@+id/textView5" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="TextView" /> 

     <EditText 
      android:id="@+id/editText5" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:ems="10" /> 

     <TextView 
      android:id="@+id/textView6" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="TextView" /> 

     <EditText 
      android:id="@+id/editText6" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:ems="10" /> 
    </LinearLayout> 
</ScrollView> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="40" 
    android:orientation="vertical" > 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Button" /> 
</LinearLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="30" 
    android:orientation="vertical" > 

    <AnalogClock 
     android:id="@+id/analogClock1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
</LinearLayout> 

+2

나는 결코 android : weightSum을 사용하지 않으며 절대로 필요하지 않습니다. 제거해보십시오. – Karakuri

+3

또한 가중치를 사용하는 경우 가중치가있는 하위 키의 높이에 '0dp'를 사용해야합니다. – Karakuri

+0

@Karakuri는 완전히 옳습니다. 또한 한 번에 크기 (너비 또는 높이) 만 "가중치"할 수 있습니다. –

답변

2

layout_weight 메커니즘은 자식 가중치에 비례 한 레이아웃의 나머지 공간을 분배한다. 조회수가 이미 fill_parent으로 모든 공간을 차지하므로 가중치 메커니즘을 배포 할 공간이 남아 있지 않습니다. 가중치로 배포 할 공간이 실제로 있도록 칭량 된 레이아웃의 어린이 높이를 0px로 설정합니다.

또한 가중치를 지정하는 것은 종종 중복됩니다. 레이아웃 자체는 하위 가중치의 합계를 계산할 수 있습니다.

+0

그리고 보충 정보로 API 레벨 8부터'fill_parent'가 사용되지 않습니다. API 레벨 8 이후로는'match_parent'를 대신 사용해야합니다. –

1

가중치에 따라 레이아웃을 설정하고 스크롤보기를 제거하려면 스크롤보기에 가중치 합계 속성이 없습니다. 그렇지 않으면 스크롤보기를 사용합니다. 스크롤보기에서 가중치 합계가 필요하지 않습니다.

+0

더 자세히 설명해 주시겠습니까? 그것은 jarled하게 보인다. – ElectronicGeek

관련 문제