我有9个列表视图应该属于单个活动。所有列表可能/可能不会一次显示在屏幕上(一次一个都很好)
答案 0 :(得分:24)
这是同一个Activity中多个ListView的合适解决方案。首先是最重要的布局文件(从ANDROID : split the screen in 2 equals parts with 2 listviews 复制,干得好!)。请注意,ListViews嵌入在它们自己的LinearLayouts中,每个LinearLayout都是相同的权重。
<LinearLayout android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<ListView android:id="@+id/list1"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
</ListView>
</LinearLayout>
<LinearLayout android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<ListView android:id="@+id/list2"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
</ListView>
</LinearLayout>
// Start java Code (you can figure out the imports)
public class AnActivity extends Activity {
private ListView lv1 = null;
private ListView lv2 = null;
private String s1[] = {"a", "b", "c", "d", "e", "f"};
private String s2[] = {"r", "s", "t", "u", "v", "w", "x"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Get UI references.
//
lv1 = (ListView) findViewById (R.id.list1);
lv2 = (ListView) findViewById (R.id.list2);
lv1.setAdapter(new ArrayAdapter<String> (this, android.R.layout.simple_list_item_1, s1));
lv2.setAdapter(new ArrayAdapter<String> (this, android.R.layout.simple_list_item_1, s2));
} // onCreate()
} // class
对不起,如果有任何错别字。我正在窗口中编辑,而不是在日食中。祝你好运!
答案 1 :(得分:5)
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:baselineAligned="false" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<ListView
android:id="@+id/listView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:visibility="visible">
</ListView>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<ListView
android:id="@+id/listView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:visibility="visible">
</ListView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
答案 2 :(得分:0)
你应该使用页面查看器,看看这个例子,希望这会对你有所帮助 http://mobile.tutsplus.com/tutorials/android/android-user-interface-design-horizontal-view-paging/