У меня есть простой LinearLayout с несколькими детьми. Весь дизайн активности в основном копируется из примера Google BluetoothChat. LinearLayout содержит 2 ListViews для отображения парных Bluetooth-устройств и устройств Bluetooth, которые можно найти (если они доступны для поиска).Android: ListView в LinearLayout давайте оставим другие макеты детей
Проблема: Если слишком много спаренных устройств, первый ListView занимает весь экран, так что ScanButton больше не виден. Не должно быть достаточно места для ScanButton, так как я работаю с android: weight.
Вот XML-код:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:id="@+id/title_paired_devices"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#666"
android:paddingLeft="5dp"
android:text="@string/deviceList_title_paired_devices"
android:textColor="#fff"
android:visibility="gone"
/>
<ListView
android:id="@+id/paired_devices"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:stackFromBottom="true"
/>
<TextView
android:id="@+id/title_new_devices"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#666"
android:paddingLeft="5dp"
android:text="@string/deviceList_title_other_devices"
android:textColor="#fff"
android:visibility="gone"
/>
<ListView
android:id="@+id/new_devices"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:stackFromBottom="true"
/>
<Button
android:id="@+id/button_scan"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Scan"
/>
</LinearLayout>
Если вес макета удаляется, то же самое произойдет, если 'ListView' содержит больше элементов. – Suhas
Использование Относительная компоновка будет работать нормально – impathuri