Высота ListView в диалоге в Android не установлена ​​в соответствии с количеством элементов в ListView;приводит к пустому пространству при меньшем количестве опций - PullRequest
0 голосов
/ 28 января 2019

Результат подходит, когда есть достаточно вариантов; image-> result в порядке , но если в списке просмотра будет меньше параметров, тогда будет пустое место;что я не хочу там быть. image-> не в порядке результат

Я хочу установить высоту, например, когда есть меньше вариантов, не должно быть никакихпустое пространствоКнопка отмены и просмотр списка.

Код для list_view.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"
android:layout_height="match_parent">

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

    <TextView
        android:id="@+id/title_textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:fontFamily="@font/quicksand_regular"
        android:text="Please select country"
        android:textAlignment="center"
        android:textSize="14sp" />


    <ListView
        android:id="@+id/dialogList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="10"
        android:background="@drawable/listview_background"
        android:choiceMode="singleChoice"></ListView>


    <Button
        android:id="@+id/cancel_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="5dp"
        android:background="@drawable/button_background"
        android:fontFamily="@font/quicksand_bold"
        android:gravity="center_horizontal"
        android:paddingLeft="50dp"
        android:paddingRight="50dp"
        android:text="cancel"
        android:textColor="#fff" />

</LinearLayout>
</RelativeLayout>

Код для list_item.xml

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

<com.rohan.myvoice.CustomTextView
    android:id="@+id/textViewStyle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:text="Text"
    android:textAlignment="center"
    android:textColor="@drawable/option_select_color"
    android:textSize="16sp" />


<View
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:layout_marginLeft="15dp"
    android:layout_marginRight="15dp"
    android:background="@color/line_light" />

</LinearLayout>

Я не могу использовать другойпредставления вроде фрагмента и тому подобное, так как в моем коде будет много изменений.

1 Ответ

0 голосов
/ 28 января 2019

Вы устанавливаете layout_weight на 10, который не требуется здесь для просмотра списка мы просто хотим использовать wrap_content в layout_heigh t: -

 <ListView
        android:id="@+id/dialogList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="10"
        android:background="@drawable/listview_background"
        android:choiceMode="singleChoice"></ListView>

Пожалуйста,проверить, используя представление Recycler вместо списка, используя мой код: -

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

    <TextView
        android:id="@+id/title_textView"
        android:layout_width="250dp"
        android:layout_height="30dp"
        android:gravity="center"
        android:layout_marginBottom="10dp"
        android:text="Please select country"
        android:textAlignment="center"
        android:textSize="14sp" />


    <android.support.v7.widget.RecyclerView
        android:id="@+id/dialogList"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:choiceMode="singleChoice" />


    <Button
        android:id="@+id/cancel_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="5dp"
        android:background="@drawable/button_background"
        android:gravity="center"
        android:text="cancel"
        android:textColor="#fff" />

</LinearLayout>
...