【问题标题】:How to get this tab image to take up the full area如何让这个标签图像占据整个区域
【发布时间】:2012-10-29 08:01:27
【问题描述】:

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

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

Android remove space between tabs in tabwidget

How to change the Tabs Images in the 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>

【问题讨论】:

    标签: android tabs


    【解决方案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);
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-05-11
        • 1970-01-01
        • 2018-09-03
        • 2012-02-03
        • 1970-01-01
        • 2012-07-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多