【问题标题】:Bottom tabs not filling the screen底部标签没有填满屏幕
【发布时间】:2014-02-14 13:26:16
【问题描述】:

我正在开发一个需要底部标签的应用程序。我已经将选项卡放在了它们的位置,但是选项卡与屏幕的底部、左侧和右侧之间有一个空白区域。 我下载了一个示例代码,它看起来正是我想要的标签,但空格不断出现。

我的申请: http://postimg.org/image/6ft0v2qyn/

我希望标签的外观: http://postimg.org/image/az9l93ymx/

抱歉,我没有足够的声望,无法直接发布图片。

XML 布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
     <!-- Framelayout to display Fragments -->
    <FrameLayout
        android:id="@+id/frame_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
<TabHost
    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="0dip"
            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:background="@drawable/tab_background" />

    </LinearLayout>

</TabHost>
<!-- Listview to display slider menu -->
</android.support.v4.widget.DrawerLayout>

添加标签的功能:

private void addTab(String labelId, int drawableId, Class<?> c)
    {
        TabHost tabHost = getTabHost();
        Intent intent = new Intent(this, c);
        TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId);

        View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false);
        TextView title = (TextView) tabIndicator.findViewById(R.id.title);
        title.setText(labelId);
        ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
        icon.setImageResource(drawableId);

        spec.setIndicator(tabIndicator);
        spec.setContent(intent);
        tabHost.addTab(spec);
        //tabHost.getTabWidget().setDividerDrawable(null);
        //tabHost.setCurrentTab(2);
    }

为函数传递参数:

addTab("Send News", R.drawable.icon_sendnews, SendNewsActivity.class);

已解决:tabHost 有一个 5dp 的填充,我不知道它是从哪里来的,但是当我删除它时,标签变成了我想要的形状:D 任何帮助表示赞赏:)

【问题讨论】:

标签: android tabs tabactivity


【解决方案1】:

可能在您的片段布局中您没有删除 边距

【讨论】:

  • 哪个片段布局?对于每个选项卡,我使用从它们各自的类调用的不同类型的布局。
猜你喜欢
  • 1970-01-01
  • 2022-11-26
  • 1970-01-01
  • 2011-02-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-27
相关资源
最近更新 更多