2017-03-06 3 views
1

내가이 레이아웃있어 작동하지 않습니다안드로이드 레이아웃 무게는

<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="6sp" 
    android:layout_marginLeft="16sp" 
    android:layout_marginRight="6sp" 
    android:layout_marginTop="6sp" > 

    <TextView android:id="@+android:id/title" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceListItem" 
     android:inputType="none" /> 

    <TextView android:id="@+android:id/summary" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:layout_below="@android:id/title" 
     android:maxLines="2" 
     android:layout_width="wrap_content" /> 

</RelativeLayout> 

<!-- Preference should place its actual preference widget here. --> 
<!-- android:id="@android:id/widget_frame" --> 

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_marginBottom="6sp" 
    android:layout_marginLeft="6sp" 
    android:layout_marginRight="6sp" 
    android:layout_marginTop="10sp" 
    android:gravity="center_vertical" 
    android:orientation="horizontal" 
    android:weightSum="1" > 

    <SeekBar 
     android:id="@+id/change_seekbar" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.8" 
     android:paddingLeft="20dip" 
     android:paddingRight="20dip" > 

    </SeekBar> 

    <TextView 
     android:id="@+id/Text_Box_seek" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="5dip" 
     android:textSize="16dip" > 
    </TextView> 
</LinearLayout> 

내가 추구하는 바는 내부 선형 레이아웃 폭의 80 %를 먹고 싶어을하지만, 탐색 바는 아주 작은 채로 남아 있습니다. 왜 공간의 나머지 부분을 차지하지 않을까요? TextView 20 % 중량의 나머지 부분을 포함

답변

3

W =

. match_parent 나에 대해 특정 값을 설정하기 위해 LinearLayout의 레이아웃 폭 변경이있는 LinearLayout 폭을 사용하는 경우 설명 rap_content 인 경우 LinearLayout의 너비는 자식에 따라 다릅니다.
또한 하위의 가중치를 설정하므로 하위의 너비는 상위에 따라 다릅니다.
=> 그럼 내가보기 당신이 방향을 사용하는 경우

1

시도 - 완벽하게 무게를 배포하는 Text_Box_seek

<TextView 
     android:id="@+id/Text_Box_seek" 
     android:layout_width="0dp" 
     android:layout_weight="0.2" 
     android:layout_height="wrap_content" 
     android:layout_margin="5dip" 
     android:textSize="16dip" > 
    </TextView> 

, 당신은 당신이 필요에 따라 모든 항목에 가중치를 부여해야합니다. 다른 사람들을 wrap_content로 설정하면 여러분이 지정한 가중치를 무시한 채로 공간을 사용할 수 있습니다.

또한 판 반 린은 폭이 parent match_해야하거나 레이아웃이 무게 배분에 영향을 미칠 것이다 (그 폭에 대한 내용에 dpened하지 않도록 모든 지정된 응답으로 편집 할 수 있습니다.

0

을 어떻게 해야할지 모르는 것 같아 (부모의 폭은 차일의 폭이 부모에 의존 차일에 따라 다름) : 그 시간 layout_width가 있어야한다 Horizontal..at 0dp 안드로이드 : layout_width = "0dp"

0

는 match_parent하는

<!-- Preference should place its actual preference widget here. --><!-- android:id="@android:id/widget_frame" --> 
     <RelativeLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="6sp" 
      android:layout_marginLeft="16sp" 
      android:layout_marginRight="6sp" 
      android:layout_marginTop="6sp"> 

      <TextView 
       android:id="@+android:id/title" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:inputType="none" 
       android:textAppearance="?android:attr/textAppearanceListItem" /> 

      <TextView 
       android:id="@+id/summary" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@android:id/title" 
       android:maxLines="2" 
       android:textAppearance="?android:attr/textAppearanceSmall" /> 

     </RelativeLayout> 

     <!-- Preference should place its actual preference widget here. --> 
     <!-- android:id="@android:id/widget_frame" --> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_marginBottom="6sp" 
      android:layout_marginLeft="6sp" 
      android:layout_marginRight="6sp" 
      android:layout_marginTop="10sp" 
      android:gravity="center_vertical" 
      android:orientation="horizontal"> 

      <SeekBar 
       android:id="@+id/change_seekbar" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="0.3" 
       android:paddingLeft="20dip" 
       android:paddingRight="20dip"> 

      </SeekBar> 

      <TextView 
       android:id="@+id/Text_Box_seek" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_margin="5dip" 
       android:layout_weight="0.7" 
       android:textSize="16dip"></TextView> 
     </LinearLayout> 

     </RelativeLayout> 
0

변경에게의있는 LinearLayout의 폭이보십시오.

0

선형 레이아웃 속성을 android:layout_width="match_parent"으로 설정하면 레이아웃 가중치가 적용됩니다. 이 답변이 도움이되기를 바랍니다.

0

Ani와 Shreya Patel이 모두 맞습니다. LinearLayout에서 layout_midth를 match_parent로 변경하면 가중치가 적용됩니다.