它可以在Android上实现吗?

时间:2011-04-21 17:48:57

标签: android listview android-activity tabview

我刚刚开始使用Android。如果有可能实现以下屏幕,请你给我一个提示:

http://i.stack.imgur.com/0Hy6W.png

左侧是列表视图,右侧是每个选项卡中带有列表视图的TabView。 如果可能的话,我应该使用哪些元素和活动?

3 个答案:

答案 0 :(得分:3)

是的。

您可以a look a at this了解Android视图的工作原理

答案 1 :(得分:2)

<强> main.xml中

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <ListView
        android:id="@+id/left_list"
        android:layout_width="100dip"
        android:layout_height="wrap_content" />
    <TabHost
        android:id="@+id/tab_host"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" />
            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">
                <ListView
                    android:id="@+id/listview1"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent" />
                <ListView
                    android:id="@+id/listview2"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent" />
                <ListView
                    android:id="@+id/listview3"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent" />
            </FrameLayout>
        </LinearLayout>
    </TabHost>
</LinearLayout>

<强> row.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/row_text"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="5dip" />
package com.stackoverflow.q5747834;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TabHost;

public class ListViewsGalore extends Activity
{
  @Override
  public void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    List listContents = new ArrayList();
    listContents.add("one");
    listContents.add("two");
    listContents.add("three");
    listContents.add("four");
    listContents.add("five");
    listContents.add("six");
    listContents.add("seven");
    listContents.add("eight");
    listContents.add("nine");
    listContents.add("ten");
    listContents.add("eleven");
    listContents.add("twelve");
    listContents.add("thirteen");
    listContents.add("fourteen");
    listContents.add("fifteen");
    listContents.add("sixteen");
    listContents.add("seventeen");
    listContents.add("eighteen");
    listContents.add("nineteen");
    listContents.add("twenty");

    ListView leftList = (ListView) findViewById(R.id.left_list);
    leftList.setAdapter(new ArrayAdapter(this, R.layout.row, listContents));

    ListView listview1 = (ListView) findViewById(R.id.listview1);
    listview1.setAdapter(new ArrayAdapter(this, R.layout.row, listContents));

    ListView listview2 = (ListView) findViewById(R.id.listview2);
    listview2.setAdapter(new ArrayAdapter(this, R.layout.row, listContents));

    ListView listview3 = (ListView) findViewById(R.id.listview3);
    listview3.setAdapter(new ArrayAdapter(this, R.layout.row, listContents));

    TabHost mTabHost = (TabHost) findViewById(R.id.tab_host);
    mTabHost.setup();

    mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("TAB 1").setContent(R.id.listview1));
    mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("TAB 2").setContent(R.id.listview2));
    mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("TAB 3").setContent(R.id.listview3));

    mTabHost.setCurrentTab(0);
  }
}

答案 2 :(得分:1)

是平板电脑的设计吗?

您必须查看碎片

http://developer.android.com/guide/topics/fundamentals/fragments.html

我希望它会对你有所帮助。