Listview и кнопки внутри scrollview android

#xml #android-studio #android-layout #android-scrollview

#xml #android-studio #android-макет #android-scrollview

Вопрос:

Я показываю пользователю все его данные внутри listview. Теперь я добавляю 4 кнопки под ним, чтобы пользователь мог редактировать / удалять/ Добавить в избранное, отменить. Listview не будет прокручиваться, но будет отображать все содержимое (Wrap_Content) фоновый Scrollview будет прокручиваться, чтобы показать все 4 кнопки внизу! Как мне сделать так, чтобы мой вид выглядел так?

Обратитесь к этому изображению

 <ListView
    android:id="@ id/lv"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@ id/l1" />

<LinearLayout
    android:id="@ id/l1"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <Button
        android:id="@ id/Fav"rounded_carddata"
        android:layout_margin="16dp"
        android:layout_width="match_parent"
        android:layout_height="50dp"/>

    <Spinner
        android:id="@ id/cancel"
        android:layout_width="match_parent"
        android:layout_height="50dp"/>

    <Button
        android:id="@ id/move"
        android:layout_width="match_parent"
        android:layout_height="50dp"/>

    <Button
        android:layout_width="match_parent"
        android:layout_height="50dp"/>


    <Button
        android:layout_width="match_parent"
        android:layout_height="50dp"/>


</LinearLayout>
 

Комментарии:

1. Привет, добро пожаловать в SO. Используйте ConstraintLayout. Какой макет лучше всего подходит для всех видов макетов

2. Эй, @Priyankagb, не могли бы вы привести мне пример для того же?

Ответ №1:

Вы можете использовать приведенный ниже код.

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

<ListView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#7C7777"
    android:layout_above="@ id/linearLayout">
</ListView>
<LinearLayout
    android:id="@ id/linearLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="4"
    android:layout_alignParentBottom="true">
    <Button
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:text="1"/>
    <Button
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:text="2"/>
    <Button
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:text="3"/>
    <Button
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:text="4"/>
</LinearLayout>
 

и это будет выглядеть так: