0

在此处输入图像描述

在这张照片中,我试图让图像占据整个黑色的顶部和底部区域。我在这里查看了这些链接,但到目前为止我没有任何运气:

http://joshclemm.com/blog/?p=136

Android删除tabwidget中选项卡之间的空间

如何更改 TabHost 中的选项卡图像

编码:

主要活动:

// Add the Tabs/////////////////////////////////////////////
    th = (TabHost) findViewById(R.id.tabhost);
    th.setup();

    specs = th.newTabSpec("tag1");
    specs.setContent(R.id.tab1);
    specs.setIndicator("", getResources().getDrawable(R.drawable.b_news));
    th.addTab(specs);

    specs = th.newTabSpec("tag2");
    specs.setContent(R.id.tab2);
    specs.setIndicator("Library");
    th.addTab(specs);

    specs = th.newTabSpec("tag3");
    specs.setContent(R.id.tab3);
    specs.setIndicator("Community");
    th.addTab(specs);

main_activity.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<TabHost
    android:id="@+id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="#ffffff" >

            <LinearLayout
                android:id="@+id/tab1"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <WebView
                    android:id="@+id/webView1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/tab2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#000000" >

                <ListView
                    android:id="@+id/libraryListView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    tools:ignore="InefficientWeight" >
                </ListView>
            </LinearLayout>

            <LinearLayout
                android:id="@+id/tab3"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#000000" >

                <ListView
                    android:id="@+id/communityListView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    tools:ignore="InefficientWeight" >
                </ListView>
            </LinearLayout>
        </FrameLayout>

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

</RelativeLayout>
4

2 回答 2

1
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
            LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    params.weight = 1.0f;
    params.gravity = Gravity.CENTER;

    mTabHost.getTabWidget().getChildAt(0).setLayoutParams(params);
    mTabHost.getTabWidget().getChildAt(1).setLayoutParams(params);
    mTabHost.getTabWidget().getChildAt(2).setLayoutParams(params);
    mTabHost.getTabWidget().getChildAt(3).setLayoutParams(params);
于 2013-12-27T12:45:43.777 回答
-1

答案在我提供的链接中。我只需要多看一点。

于 2012-10-31T13:24:51.783 回答