我有一个带有项目的可滚动ListView(如http://developer.android.com/resources/tutorials/views/hello-listview.html).我正在使用一个ArrayAdapter项目并将其用作参数setListAdapter.现在我想在屏幕底部添加一个按钮,该按钮不会随列表一起滚动.有人可以给我一些提示或发布代码片段如何可能吗?
Sri*_*lla 104
如果您的活动扩展了ListActivity,那么您需要以下内容:
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView android:id="@android:id/list"
android:layout_height="0dip"
android:layout_width="match_parent"
android:layout_weight="1" />
<Button android:id="@+id/btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
请注意,listview的layout_weight设置为1.这将使按钮固定在底部的位置.希望有所帮助.祝好运!
Hou*_*ine 14
您可以使用RelativeLayout来修复布局底部的按钮,并在其上方添加listView,如下所示:
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent">
<Button android:id="@+id/btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
<ListView
android:id="@android:id/list"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_above="@id/btn" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
31775 次 |
| 最近记录: |