相关疑难解决方法(0)

使用带有选项卡布局的自定义视图时,无法从选项卡中删除填充

我在自定义视图中添加了相对布局,并在选项卡布局中添加了它.我使用白色背景的标签,并没有在标签自定义布局中应用任何填充.但是后来我也在填充选项卡上,因为我在选项卡中显示了一些灰色背景,好像android在内部应用填充到选项卡.我试图显示三个文本视图,我可以做,但其中一个是因为填充应用于选项卡而截断.此外,我希望标签具有一致的背景颜色.

这是我的布局代码:

activity_home.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.customtablayoutapplication.HomeActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />


    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_home" />


</android.support.design.widget.CoordinatorLayout>



fragment_home.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:theme="@style/AppTheme.AppBarOverlay"
    tools:context="com.customtablayoutapplication.HomeFragment"
    tools:showIn="@layout/activity_home">

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabGravity="fill"
        app:tabMode="fixed" />

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</LinearLayout>


custom_tab.xml`enter code here`

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:background="@android:color/white"
    android:layout_height="match_parent"
    android:layout_gravity="center">

    <TextView
        android:id="@+id/total_request_count"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:text="12"
        android:textAllCaps="false"
        android:visibility="gone"
        android:textColor="@color/colorPrimaryDark"
        android:textSize="12sp" /> …
Run Code Online (Sandbox Code Playgroud)

customization android-custom-view android-tablayout

25
推荐指数
4
解决办法
2万
查看次数