3

I can create five tabs using ActionBarSherlock that will not scroll and all fit on the screen. After I set one of the tabs to use an image, all the tabs become as wide as that tab, which itself becomes larger than the image I am using. How can I show five tabs, each with an image? I do not want them to scroll, but all be visible at once. Here is how I am setting the tab with the image:

tab1.setIcon(R.drawable.tab_home_unselect);

enter image description here

4

1 回答 1

0

我想你将不得不使用填充、边距、布局和图像的大小......

这是带有图像和文本的选项卡布局示例:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/tab_item"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
    android:padding="2dip" >

    <ImageView
        android:id="@+id/tab_icon"
        android:layout_width="28dip"
        android:layout_height="28dip"
        android:layout_marginBottom="1dip" />

    <TextView
        android:id="@+id/tab_title"
        android:layout_width="wrap_content"
        android:layout_height="0dip"
        android:layout_marginBottom="2dp"
        android:layout_weight="1"
        android:gravity="center"
        android:textColor="@android:color/white"
        android:textSize="12sp" />

</LinearLayout>

以及添加它们的方法

private View getTabIndicator(String text, int drawable) {

    View indicator = _inflater.inflate(R.layout.abs_tab, null);
    ((TextView) indicator.findViewById(R.id.tab_title)).setText(text);
    ((ImageView) indicator.findViewById(R.id.tab_icon)).setImageResource(drawable);
    return indicator;
}
于 2013-07-08T09:23:33.960 回答