在android中使线性布局停留在屏幕底部
我正在制作一个使用这些视图的 Android 应用程序:(
根)- LinearLayout (根的子级) - ListView + 该列表视图下方的 3 个其他线性布局。但是,一旦我将许多项目添加到列表视图中,布局就会被放置在屏幕之外。我不想这样做。我怎样才能做到这一点?这样所有三个线性布局都保留在屏幕底部???请帮忙并提前致谢!
我的屏幕 XML 代码:
<?xml version="1.0" encoding="utf-8"?>
LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
android:orientation="vertical" >
<TextView
android:id="@+id/NotesWelcomeTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/NotesWelcomeText" />
<ListView
android:id="@+android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView
<LinearLayout
android:id="@+id/DeleteAllItemsFromListViewLinearLayout"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:visibility="invisible" >
<Button
android:id="@+id/CancelButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Cancel" />
<Button
android:id="@+id/DeleteAllButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Delete" />
</LinearLayout>
<LinearLayout
android:id="@+id/DeleteItemFromListViewLinearLayout"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:visibility="invisible" >
<Button
android:id="@+id/CancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Cancel" />
<Button
android:id="@+id/DeleteButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Delete" />
</LinearLayout>
<LinearLayout
android:id="@+id/AddItemToListViewLinearLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone" >
<EditText
android:id="@+id/AddItemToListViewEditText"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_weight="1" >
</EditText>
<Button
android:id="@+id/AddItemToListViewButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/Add" />
</LinearLayout>
</LinearLayout>
I am making an android application that uses these views:
(Root) - LinearLayout
(Child of root) - ListView + 3 other linearlayouts beneeth that listview. But once i add to many items to the listview, the layouts are being placed outside of the screen. Which i don't want to. How can i make this happen? So that all of the three linearlayouts stay on the screen, at the bottom??? Please help and thanks in advance!
My screen XML code:
<?xml version="1.0" encoding="utf-8"?>
LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
android:orientation="vertical" >
<TextView
android:id="@+id/NotesWelcomeTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/NotesWelcomeText" />
<ListView
android:id="@+android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView
<LinearLayout
android:id="@+id/DeleteAllItemsFromListViewLinearLayout"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:visibility="invisible" >
<Button
android:id="@+id/CancelButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Cancel" />
<Button
android:id="@+id/DeleteAllButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Delete" />
</LinearLayout>
<LinearLayout
android:id="@+id/DeleteItemFromListViewLinearLayout"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:visibility="invisible" >
<Button
android:id="@+id/CancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Cancel" />
<Button
android:id="@+id/DeleteButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Delete" />
</LinearLayout>
<LinearLayout
android:id="@+id/AddItemToListViewLinearLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone" >
<EditText
android:id="@+id/AddItemToListViewEditText"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_weight="1" >
</EditText>
<Button
android:id="@+id/AddItemToListViewButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/Add" />
</LinearLayout>
</LinearLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个,你必须再次添加字符串引用和背景,我删除了它们,这样就不会出现错误
Try this, you'll have to add the string references and background again, I removed them so I wouldn't have errors
将 ListView 的权重设置为 0,并将其高度设置为 0。这将告诉 ListView 只占用其他视图未使用的空间。
Give your ListView a weight of 0 and set its height to 0. This will tell the ListView to only take up the space that is not use by other views.