In der folgenden XML versuche ich ein Layout zu zeichnen, das zwei Blöcke (ein LinearLayout und ein TextView) enthält. Ich möchte, dass das LinearLayout 5 mal größer ist als das TextView. Dieses XML erzeugt genau das Gegenteil von dem, was ich erwartet habe, das TextView benötigt 5 mal mehr Speicherplatz als das LinearLayout. Beachten Sie, dass ich die Breite beider Elemente auf 0dp gesetzt habe, was ein übliches Versehen ist.layout_weight arbeitet gegenüber von dem, was es sollte
<?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:paddingLeft="15dp"
android:paddingRight="15dp"
android:layout_gravity="center_vertical"
android:weightSum="6"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="5" >
<TextView
android:id="@+id/result_title_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="Arial"
android:textColor="#222222"
android:textSize="14sp"/>
<TextView
android:id="@+id/result_info_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="Arial"
android:textColor="#777777"
android:textSize="12sp" />
</LinearLayout>
<TextView
android:id="@+id/result_distance_textview"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fontFamily="Arial"
android:textColor="#ffffffff"
android:textSize="14sp" />
</LinearLayout>
EDIT: Bei diesem Layout ist eigentlich ein Listenelement, das in dieser Liste enthalten ist:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/results_list_fragment_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="15dp" >
<ListView
android:id="@+id/search_results_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/scrollable_content_background"
android:divider="@drawable/listview_divider"
android:dividerHeight="1dp" >
</ListView>
</LinearLayout>
set: android: layout_weight = "1" für lineares Layout und Android: layout_weight = "5" für Text. dh. Tausche dort Gewicht. – Cropper
Ja, ich weiß, das funktioniert, aber die Frage ist mehr warum? es sollte das entgegengesetzte Verhalten haben. – TrtG
Das ist .... falsch. Kannst du einen Screenshot hinzufügen? Wenn Sie kürzlich die Reihenfolge Ihrer Layouts geändert haben, versuchen Sie es mit einem sauberen Build. – Geobits