android - 约束布局下的ListView在预览中消失

标签 android listview android-listview

输出png

下面是我的 Activity xml: 我已从支持库迁移到 androidx。

有什么办法可以实现吗?

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
        <AutoCompleteTextView
            android:id="@+id/partyname"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:background="@drawable/rounded_edittext"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="5dp"
            android:layout_marginStart="5dp"
            android:hint="@string/firm_name"
            android:padding="5dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toTopOf="parent"/>
    <LinearLayout
        android:id="@+id/billform"
        android:layout_marginTop="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginEnd="5dp"
        android:layout_marginStart="5dp"
        android:layout_marginLeft="5dp"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:orientation="vertical"
        android:background="@drawable/rounded_buttons"
        app:layout_constraintTop_toBottomOf="@id/partyname">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <AutoCompleteTextView
                android:id="@+id/identifier"
                android:layout_height="50dp"
                android:layout_width="0dp"
                android:padding="5dp"
                android:layout_marginEnd="8dp"
                android:textSize="16sp"
                android:textAllCaps="true"
                android:hint="@string/code_article"
                android:background="@drawable/rounded_edittext"
                android:layout_marginRight="8dp"
                android:layout_alignParentStart="true"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:layout_toLeftOf="@+id/add"
                android:layout_toStartOf="@+id/add" />
            <Button
                android:id="@+id/add"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/rounded_buttons"
                android:text="@string/add"
                android:textAllCaps="true"
                android:textSize="18sp"
                android:layout_centerVertical="true"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true" />
        </RelativeLayout>
    </LinearLayout>
    <ListView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintTop_toBottomOf="@id/billform"
        app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>

天知道为什么,listView 在预览中不可用。 当根是线性布局时它起作用。我尝试在约束布局中创建线性布局,但没有成功

最佳答案

android:layout_height="0dp"

这可能是你的问题,或者如果你说的是看不到项目,那么它可能是 android studio 中的错误,因为我尝试添加另一个 ConstraintLayout 但没有任何运气。

This answer might help

我想将我的答案添加为评论,但 StackOverflow 不允许。

关于android - 约束布局下的ListView在预览中消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57104326/

相关文章:

android - 如何在对话框中设置 ListView 的 "onItemSelectedListener"。安卓

android - 如何制作可滚动的 ListView 但不填满整个屏幕?

android - 如何在支持和不支持的情况下在 ListVIew 中使用 MultiChoiceModeListener?

android - 更改 android.R.layout.simple_list_item_multiple_choice 的文本颜色

android - 使用 SimpleAdapter 将背景图像应用于 ListView

android - 谷歌健身许可

触摸通知的android打开应用程序

安卓 ListView : how to get the items on screen?

java - Wicket - 在 wicket 表中动态添加列

android - 如何使RealtiveLayout中的ToggleButton和ImageButton高度相同?