在ListView上单击按钮 [英] Button over a ListView
本文介绍了在ListView上单击按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在ListView
上放置Button
?像这样的图像?
How is it possible to place a Button
over a ListView
? Like this image?
我尝试过:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:text="Button" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ListView
android:id="@+id/listView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
</FrameLayout>
但是Button
无法访问...
ListView
和Button
都必须可访问.
But the Button
is inaccessible...
Both the ListView
and the Button
must be accessible.
推荐答案
首先,您应该使用RelativeLayout
; FrameLayout
用于最佳地保存单个子元素.
Firstly, you should be using RelativeLayout
; FrameLayout
is used to hold a single child element optimally.
第二,从上到下->从后到前依次绘制布局.因此,您希望在XML文件中的Button
下方.
Second, the layout is drawn in order from top to bottom -> back to front. Therefore you want your Button
below it in the XML file.
最后,您应该使用的是align
,而不是align
.
Lastly, instead of gravity
you should be using align
.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ListView
android:id="@+id/listView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:text="Button" />
</RelativeLayout>
这篇关于在ListView上单击按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文