0

タブホスト内の画像のデフォルト位置を変更する必要があります。任意のタブをクリックしたときに、各タブの上部にポインティング画像として画像を表示したい..だから、タブの横にある画像のデフォルト位置を変更する方法ウィジェット? 表示タブ ウィジェットの単純な 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:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="5dp">

    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="5dp"
        android:layout_weight="1"/>

    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:layout_marginBottom="-4dp"/>

</LinearLayout>

4

1 に答える 1

0

setIndicator (ビュー ビュー)tabwidgetを使用して、任意のビューにインフレートできます。

public TabHost.TabSpec setIndicator (View view)
Since: API Level 4

Specify a view as the tab indicator.

例:

TabWidget レイアウト: tab_widget_custom.xml

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:background="@drawable/tabwidget_selector"
    android:gravity="center"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/tabIndicatorIcon"
        android:layout_width="28dp"
        android:layout_height="28dp"
        android:layout_marginTop="2dp" />

    <TextView
        android:id="@+id/tabIndicatorText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="2dp"
        android:textColor="@color/white" />

</LinearLayout>

アクティビティでメソッド リターンtabwidgetビューを作成する

private View getTabIndicatorView(Context context, String tag, int drawable) {
        View view = LayoutInflater.from(context).inflate(
                R.layout.tab_widget_custom, null);
        TextView tv = (TextView) view.findViewById(R.id.tabIndicatorText);
        tv.setText(tag);
        ImageView tabIndicatorIcon = (ImageView) view
                .findViewById(R.id.tabIndicatorIcon);
        tabIndicatorIcon.setBackgroundResource(drawable);
        return view;

    }

この方法で新規作成tabwidget

private void initTab() {
        Intent intent;
        TabHost.TabSpec spec;

        spec = tabHost.newTabSpec("Inbox").setIndicator(
                getTabIndicatorView(MainTabActivity.this, "Inbox",
                        R.drawable.inbox_tab_selector));

        spec.setContent(intent);
        tabHost.addTab(spec);

        }
于 2012-10-03T15:47:54.217 に答える