gpt4 book ai didi

android - ListView 隐藏了 EditText

转载 作者:行者123 更新时间:2023-11-29 14:28:22 28 4
gpt4 key购买 nike

我是 Android 新手,正在阅读 Wrox 的专业 android 4 应用程序开发书籍。在本书的第 4 章中,它解释了如何修改现有的 TextView 。我面临的问题是我的应用程序中的 ListView 隐藏了编辑文本框。它是隐藏的(可以在背景中看到)但仍然有效,可以通过它向列表中添加更多内容。下面是我的主要 Activity xml 的代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<EditText
android:id="@+id/myEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="@string/addItemContentDescription"
android:hint="@string/addItemHint"
/>
<ListView
android:id="@+id/myListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>

和我的 todolist_item xml

<?xml version="1.0" encoding="utf-8"?>
<com.example.wroxexample.ToDoListItemView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:scrollbars="vertical"
android:textColor="@color/notepad_text"
android:fadingEdge="vertical"
/>

最佳答案

第一个选项是使用 LinearLayout而不是 RelativeLayout .

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<EditText
android:id="@+id/myEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="@string/addItemContentDescription"
android:hint="@string/addItemHint"
/>
<ListView
android:id="@+id/myListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>

RelativeLayout 允许您相对于其他元素定位元素。

另一方面,LinearLayout 会将元素按照它们在 xml 文件中出现的顺序逐个放置。

您的第二个选择是保留您的 RelativeLayout 并将以下标记添加到您的 ListView:

android:layout_below="@id/myEditText"

这会将 ListView 定位在 EditText 的下方。

关于android - ListView 隐藏了 EditText,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11864225/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com