2017-03-06 5 views
1

ich dieses Layout bekam:Android Layout Gewicht funktioniert nicht

<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> 

Ich mag die Suchleiste 80% der Breite in dem inneren linearen Layout nehmen, aber die Suchleiste bleibt sehr klein. Warum wird es den Rest des Raumes nicht nehmen?

Antwort

3

ändern des Layouts Breite Ihres LinearLayout match_parent oder einen bestimmten Wert für sie festgelegt.

Erklären Wenn Sie Linearlayout Breite verwenden = w rap_content, die Breite von LinearLayout hängt von den Childs ab.
Und Sie legen auch das Gewicht für die Kinder, so dass die Breite des Kindes von den Eltern abhängt.
=> (Breite der Eltern auf Kind abhängen, eine Breite von Childs auf Eltern abhängen), dann denke ich, die Ansicht wird nicht wissen, was

1

Versuchen einschließlich der restlichen 20% Gewicht in der TextView - 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> 

Für Gewicht zu verteilen perfekt, haben Sie Gewicht auf alle Elemente zuweisen nach dem, was Sie brauchen. Wenn Sie andere auf wrap_content setzen, nehmen sie Platz unter Vernachlässigung der von Ihnen angegebenen Gewichtung.

EDIT

auch als Phan Van Linh beantwortet sollte die Breite parent oder jede angegebene match_ werden, so dass das Layout nicht auf dessen Inhalt für seine Breite dpened hat (die Gewichtsverteilung beeinflussen.

0

tun, wenn Sie Orientierung verwenden: Horizontal..at, dass die Zeit layout_width sein sollte 0DP android: layout_width = "0DP"

0

Versuchen Sie dieses,

<!-- 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

ändern der Breite des Linearlayout match_parent.

0

versuchen Sie einfach, Ihre lineare Layout-Eigenschaft als android:layout_width="match_parent", dann Layout-Gewicht wird funktionieren. hoffe diese antwort wird dir helfen.

0

Ani und Shreya Patel beide richtig, ändern Sie einfach layout_midth zu match_parent in Ihrem LinearLayout und das Gewicht wird funktionieren.

Verwandte Themen