在Android上可以实现吗?

发布于 2024-11-02 21:41:57 字数 211 浏览 2 评论 0原文

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

https://i.sstatic.net /0Hy6W.png

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

I've just started working on Android. Could you please give me a tip if it's possible to realize the following screen:

https://i.sstatic.net/0Hy6W.png

In the left side there is listview and in the right there is TabView with listviews in each tab.
And if it`s possible, what elements and activities should I use?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

只是偏爱你 2024-11-09 21:41:57

是的。

您可以看看这个来了解 Android 视图的工作原理

Yes it is.

You can have a look a at this to understand how Android views work

橘香 2024-11-09 21:41:57

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);
  }
}

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);
  }
}
嘴硬脾气大 2024-11-09 21:41:57

是为平板电脑设计的吗?

您必须查看片段

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

希望对您有所帮助。

Is a design for tablets?

You must take a look to the Fragments

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

I hope it'll help you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文