带图像的自定义标签栏

时间:2014-06-04 08:48:20

标签: android tabs

我正在尝试创建一个标签栏,如下图所示(即左侧有一些图像的标签栏)。

白色部分是两个图像,而黑色部分是标签标签

任何人都可以指导我做同样的事吗?

2 个答案:

答案 0 :(得分:0)

使用actionBar.addTab(actionBar.newTab() //.setText(mSectionsPagerAdapter.getPageTitle(i)) .setCustomView(view) .setTabListener(this)); 在这里,您可以自定义布局并将其解析为视图 见[How to set a custom View in ActionBar's navigation tabs and make the tabs adapt to its height?

答案 1 :(得分:0)

我设法在不使用操作栏的情况下获得解决方法。只是一些XML代码调整,我很高兴。这是我做的:

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

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
     >

    <RelativeLayout
        android:id="@+id/linear"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/tab_bg" >

       <LinearLayout 
           android:orientation="horizontal"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content">
        <ImageView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/options"
            android:layout_gravity="center"
            android:layout_marginLeft="10dp"/>
        <ImageView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/img"
            android:layout_marginLeft="10dp"/>
        </LinearLayout>

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="300dp"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"/>
    </RelativeLayout>

    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignLeft="@+id/linear"
        android:layout_below="@+id/linear">
    </FrameLayout>
</RelativeLayout>

</TabHost>
相关问题