将按钮添加到listactivity [英] Add buttons to a listactivity
问题描述
我有一个ListActivity布局。要修改我已经使用的菜单选项列表。但是,除去一对夫妇在屏幕上点击我想补充两个按钮在屏幕始终可见并没有受到影响,如果列表中滚动的按钮。
I have a layout for a ListActivity. To modify the list I have used menu-options. But to remove a couple of "clicks" on the screen I'd like to add two buttons in the button of the screen that is always visible and not affected if the list is scrolled.
我的问题是,我不知道如何添加这些按钮。我已经尝试了几个解决方案,但最好的,我管理无论是列表或布局的按钮在前看不见。看来,我不能得到两个按钮和列表中可见在同一时间。
My problem is that I don't know how to add these buttons. I have tried a couple of solutions but the best I managed either the list or the buttons disapears from the layout. Seems that I can't get both buttons and list visible at the same time.
所以我的问题是,如何建立一个布局,我可以有两个按钮和列表?
So my question is how to create a layout where I can have both buttons and the list?
在此先感谢 罗兰
推荐答案
从<一个href="http://developer.android.com/reference/android/app/ListActivity.html">http://developer.android.com/reference/android/app/ListActivity.html:
ListActivity具有默认布局由单个,全屏列表在屏幕的中心。但是,如果你的愿望,你可以通过设置使用的setContentView自己的看法布局()中的onCreate自定义屏幕布局()。要做到这一点,你自己的看法必须包含id为一个ListView对象@android:ID /表
"ListActivity has a default layout that consists of a single, full-screen list in the center of the screen. However, if you desire, you can customize the screen layout by setting your own view layout with setContentView() in onCreate(). To do this, your own view MUST contain a ListView object with the id "@android:id/list""
编辑:下面是一个例子:
该ListActivity可能是这样创建的:
The ListActivity may be created like this:
public class ListViewTest extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] values = {"One", "Two", "Three"};
setListAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, values));
setContentView(R.layout.main);
}
}
在的main.xml
布局如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@android:id/list"></ListView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Test button"
android:id="@+id/TestButton"></Button>
</LinearLayout>
这篇关于将按钮添加到listactivity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!