【问题标题】:How to add margin between tab backgrounds inside tab layout android?如何在标签布局android中的标签背景之间添加边距?
【发布时间】:2021-12-31 13:08:18
【问题描述】:

2 个标签具有单独的带边框背景,它们与背景之间应该有距离。

【问题讨论】:

    标签: java android xml android-layout tabs


    【解决方案1】:

    您可以添加这两个属性:

    <android.support.design.widget.TabLayout
    ...
    app:tabPaddingStart="10dp" 
    app:tabPaddingEnd="10dp" />
    

    我之前发现了同样的问题,你可以在那里找到答案:https://stackoverflow.com/a/36511524/9040853

    希望我的回答对你有用。

    【讨论】:

    • 感谢您的回答,但我想要两个标签的单独背景。 “tabPadding”增加了空间,但在单个选项卡布局中,一个背景而不是两个选项卡的两个单独背景。
    • 你的意思是你想要两个标签的背景。一个背景和它上面的标签对吗?
    • 查看这个答案stackoverflow.com/a/32613364/9040853希望对你有帮助。
    【解决方案2】:

    欢迎, 将这样的视图(那个勾号)保持在另一个视图之上称为Overlapping Layouts,您可以使用相对布局来做到这一点,画廊视图和图像视图将重叠

    <RelativeLayout 
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/gallerylayout"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">
      <Gallery
        android:id="@+id/overview"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
      />
      <ImageView
        android:id="@+id/navigmaske"
        android:background="#0000" /*use #000000 for black colour*/
        android:src="@drawable/navigmask" //put your image here
        android:scaleType="fitXY"
        android:layout_alignTop="@id/overview"
        android:layout_alignBottom="@id/overview"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
      />
    </RelativeLayout>
    

    Reference post

    【讨论】: