【问题标题】:Is it realizable on Android?它可以在Android上实现吗?
【发布时间】:2011-08-10 12:12:41
【问题描述】:

我刚刚开始在 Android 上工作。如果可以实现以下屏幕,请给我一个提示:

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

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

【问题讨论】:

    标签: android listview android-activity tabview


    【解决方案1】:

    是的。

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

    【讨论】:

    • 据我了解,我应该将 ListActivity 用于左侧,将 TabActivity 用于右侧。如何实现一屏实现?
    • 你需要把它们都放在一个RelativeLayout中,并指定一个在另一个的左边
    【解决方案2】:

    ma​​in.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);
      }
    }

    【讨论】:

      【解决方案3】:

      是平板电脑的设计吗?

      你必须看看碎片

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

      希望对你有帮助。

      【讨论】:

        猜你喜欢
        • 2020-03-14
        • 2011-08-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-02-09
        • 1970-01-01
        • 1970-01-01
        • 2010-09-16
        相关资源
        最近更新 更多