android - 约束布局下的ListView在预览中消失
问题描述
输出png
所以下面是我的活动 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 却没有任何运气。
我想将我的答案添加为评论,但 StackOverflow 不会让我这样做。
推荐阅读
- python - 在 tkinter 中更新文本框小部件
- jekyll - 在 Jekyll 中,如何在子文件夹中添加指向页面的链接?
- c# - 多次等待后,控制器中的 HTTPContext.Current 为空
- java - Android在create方法上触发向右滑动
- eclipse-plugin - 如何通过代码优先启用和设置自动保存的时间间隔
- validation - 带有 EntityManagerInterface 的 Symfony 4.1 自定义验证器不起作用
- spring - 创建名为“requestMappingHandlerMapping”的 bean 时出错
- xamarin.forms - 无法使用 Xamarin.Forms 中的 F# 异步支持观察页面导航
- c# - 参考和对象之间的实际差异
- javascript - Redux 形式或简单形式