在Android的垂直选项卡 [英] Vertical tabs in Android

查看:218
本文介绍了在Android的垂直选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Android的垂直选项卡中包含的图像。

I want to make vertical tabs in Android like below image.

我看到下面的链接比如垂直的标签。

I had see example for vertical tabs from below link.

<一个href="http://stackoverflow.com/questions/4149953/androidorientation-vertical-does-not-work-for-tabwidget">Click这里

在这个环节回答了一些意见和评论他们的份额code,但大型上传的链接已过期。

In this link answer has some comments and in comments they had share code but the link of mega-upload is expired.

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

I had try many ways but not able to display tabs vertical. When I am trying according to link the tabs can not be display. Please help me

推荐答案

在我使用的标签,我通常只是隐藏tabwidget标签设置的android可视性走了。

When I use tabs, I normally just hide the tabwidget tag by setting android visibility as gone.

和添加按钮来充当标签按钮的

And add buttons to act as the tab buttons like

这是修改,使垂直选项卡按钮

THIS IS MODIFIED TO MAKE VERTICAL TAB BUTTONS

<?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>

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

and I add a button click handler

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

When I use this method, it gives me more freedom to style the tab buttons. The above xml is for horizontal tab buttons but you easily make it vertical but editing it a bit. Just make sure you need the Tahbost,Tabwidget and a framelayout with @android:id/tabcontent as the id.

这篇关于在Android的垂直选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆