在Android的垂直选项卡

问题描述 投票:12回答:1

我想使垂直选项卡中的Android像下面的图像。

我曾看到从下面的链接竖直突出的例子。

Click here

在这个环节答案有一些评论和意见他们共享代码,但mega-upload的链接已过期。

我曾尝试了很多方法,但无法显示选项卡垂直。当我试图根据标签链接无法显示。请帮我

android android-tabhost
1个回答
10
投票

当我使用的标签,我通常只是隐藏设置的Android能见度不见了tabwidget标签。

并添加按钮来充当像标签按钮

这是修改,使垂直标签按钮

<?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:orientation="horizontal" 
        android:layout_width="fill_parent" android:layout_height="fill_parent">
        <FrameLayout android:layout_width="0dip" 
            android:layout_height="fill_parent" android:layout_weight="0.2">
        <TabWidget android:id="@android:id/tabs" 
                android:layout_width="fill_parent" 
                android:layout_height="wrap_content"
                android:visibility="gone"/>
            <LinearLayout android:layout_width="fill_parent"  
                android:layout_height="fill_parent"
                android:orientation="vertical">
                <Button android:layout_height="0dip" 
                    android:layout_width="fill_parent" 
                    android:layout_weight="1.0"
                android:background="@drawable/ic_tab_artists"               
                    android:id="@+id/artist_id" 
                    android:onClick="tabHandler"/>
                <Button android:layout_height="0dip" 
                    android:layout_width="fill_parent" 
                    android:layout_weight="1.0"
                android:background="@drawable/ic_tab_artists"  
                    android:id="@+id/album_id" 
                    android:onClick="tabHandler"/>
                <Button android:layout_height="0dip" 
                    android:layout_width="fill_parent" 
                    android:layout_weight="1.0"
                android:background="@drawable/ic_tab_artists"   
                    android:id="@+id/song_id" 
                    android:onClick="tabHandler"/>
        </LinearLayout> 
    </FrameLayout>       
    <FrameLayout android:id="@android:id/tabcontent" 
        android:layout_width="0dip" 
        android:layout_height="fill_parent" android:layout_weight="0.8"/>
</LinearLayout>

我添加一个按钮单击处理程序

public void tabHandler(View target){
    artistButton.setSelected(false);
    albumButton.setSelected(false);
    songButton.setSelected(false);
    if(target.getId() == R.id.artist_id){
        tabHost.setCurrentTab(0);
        artistButton.setSelected(true);
    } else if(target.getId() == R.id.album_id){
        tabHost.setCurrentTab(1);
        albumButton.setSelected(true);
    } else if(target.getId() == R.id.song_id){
        tabHost.setCurrentTab(2);
        songButton.setSelected(true);
    }
}

当我用这个方法,它给了我更多的自由风格的标签按钮。上面的XML是用于水平选项卡按钮,但你很容易使垂直的,而是编辑它一下。只要确保你需要的Tahbost,Tabwidget与@android一个的FrameLayout:ID / tabcontent作为id。

© www.soinside.com 2019 - 2024. All rights reserved.