簡體   English   中英

如何在標簽下添加一個expandablelistview?

[英]How to add an expandablelistview under tab?

如何在標簽下添加一個expandablelistview? 有沒有一種方法可以將expandablelistview添加到選項卡? 我的意思是單擊該選項卡,然后僅顯示一個expandablelistview,而不更改活動。 請幫我! 非常感謝!

可以做到。 下面的基礎知識。

tablayout.xml

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:padding="5dp" >
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="30dp"
            android:gravity="bottom" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp" >
            <!-- General Info Tab -->
            <LinearLayout
                android:id="@+id/general_tab"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" >
            </LinearLayout>
            <!-- Tool Tab -->
            <LinearLayout
                android:id="@+id/list_tab"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" >
                <ExpandableListView
                    android:id="@+id/list1"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="1"
                    android:drawSelectorOnTop="false" />
            </LinearLayout>
        </FrameLayout>
    </LinearLayout
</TabHost>

TabDemo.java

public class TabDemo extends TabActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tablayout);

        tabHost = getTabHost();
        TabHost.TabSpec spec;
        spec = tabHost.newTabSpec("General").setIndicator("General")
                .setContent(R.id.general_tab);
        tabHost.addTab(spec);
        spec = tabHost.newTabSpec("List").setIndicator("List")
                .setContent(R.id.list_tab);
        tabHost.addTab(spec);
        populateTabs();  // your method to populate the tabs
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM