Android 由于选择器重叠,父布局角不可见

Android 由于选择器重叠,父布局角不可见,android,android-layout,textview,android-tabs,android-selector,Android,Android Layout,Textview,Android Tabs,Android Selector,Im尝试使用具有2个文本视图的圆形线性布局构建选项卡 我想要以下输出 发生的情况如下 应用于textview的选择器将绘制在父布局可绘制的顶部,因此角点不可见。我无法将角点添加到textview选择器,因为它将使每个textview中的所有4个角点变圆 我还考虑过使用特定的角点,即塑造每个文本视图,但tht会增加每个文本视图的可绘制数量,这不是一个灵活的解决方案,将来我可能会选择使用更多的选项卡 请大家推荐一个通用的xml解决方案,这样我就可以在不影响父布局角的情况下更改TextView的背

Im尝试使用具有2个文本视图的圆形线性布局构建选项卡

我想要以下输出

发生的情况如下

应用于textview的选择器将绘制在父布局可绘制的顶部,因此角点不可见。我无法将角点添加到textview选择器,因为它将使每个textview中的所有4个角点变圆

我还考虑过使用特定的角点,即塑造每个文本视图,但tht会增加每个文本视图的可绘制数量,这不是一个灵活的解决方案,将来我可能会选择使用更多的选项卡

请大家推荐一个通用的xml解决方案,这样我就可以在不影响父布局角的情况下更改TextView的背景了吗

我的代码 布局


layout\u background.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:dither="true"
    android:shape="rectangle" >

    <stroke android:width="1dp" android:color="#4c8bff"/>
    <corners android:radius="5dp" />
    <solid android:color="#FFFFFFFF" />

</shape>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true" android:drawable="@drawable/tab_selected"/>
 <!-- selected -->
    <item android:state_pressed="true" android:drawable="@drawable/tab_pressed"/>
 <!-- pressed -->
    <item android:state_focused="true" android:drawable="@drawable/tab_pressed"/>
 <!-- focused -->
    <item android:drawable="@drawable/tab_normal"/>
 <!-- default -->    
</selector>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="#4c8bff" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:dither="true"
    android:shape="rectangle" >

    <stroke
        android:width="2dp"
        android:color="@color/custom_tab_selected" />

    <corners android:radius="5dp" />

    <solid android:color="#FFFFFFFF" />

    <padding
        android:bottom="2dp"
        android:left="2dp"
        android:right="2dp"
        android:top="2dp" />

</shape>
  <dimen name="custom_tab_layout_radius">4dp</dimen>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_selected="true">
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <solid android:color="@color/custom_tab_selected" />
            <corners android:bottomLeftRadius="@dimen/custom_left_tab_bottomLeftRadius" 
                android:bottomRightRadius="@dimen/custom_left_tab_bottomRightRadius" 
                android:topLeftRadius="@dimen/custom_left_tab_topLeftRadius" 
                android:topRightRadius="@dimen/custom_left_tab_topRightRadius" />
        </shape>
    </item>
    <!-- selected -->

    <item android:state_pressed="true">
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <solid android:color="@color/custom_tab_pressed" />
            <corners android:bottomLeftRadius="@dimen/custom_left_tab_bottomLeftRadius" 
                android:bottomRightRadius="@dimen/custom_left_tab_bottomRightRadius" 
                android:topLeftRadius="@dimen/custom_left_tab_topLeftRadius" 
                android:topRightRadius="@dimen/custom_left_tab_topRightRadius" />
        </shape>
    </item>
    <!-- pressed -->

    <item android:state_focused="true">
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <solid android:color="@color/custom_tab_pressed" />
            <corners android:bottomLeftRadius="@dimen/custom_left_tab_bottomLeftRadius" 
                android:bottomRightRadius="@dimen/custom_left_tab_bottomRightRadius" 
                android:topLeftRadius="@dimen/custom_left_tab_topLeftRadius" 
                android:topRightRadius="@dimen/custom_left_tab_topRightRadius" />
        </shape>       
    </item>
    <!-- focused -->

    <item>
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <solid android:color="@color/custom_tab_normal" />
            <corners android:bottomLeftRadius="@dimen/custom_left_tab_bottomLeftRadius" 
                android:bottomRightRadius="@dimen/custom_left_tab_bottomRightRadius" 
                android:topLeftRadius="@dimen/custom_left_tab_topLeftRadius" 
                android:topRightRadius="@dimen/custom_left_tab_topRightRadius" />
        </shape>
    </item>
    <!-- default -->

</selector>
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- LEFTMOST TAB -->
    <dimen name="custom_left_tab_topLeftRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_left_tab_bottomLeftRadius">0dp</dimen>
    <dimen name="custom_left_tab_topRightRadius">0dp</dimen>
    <dimen name="custom_left_tab_bottomRightRadius">@dimen/custom_tab_layout_radius</dimen>

    <!-- RIGHTMOST TAB -->
    <dimen name="custom_right_tab_topLeftRadius">0dp</dimen>
    <dimen name="custom_right_tab_bottomLeftRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_right_tab_topRightRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_right_tab_bottomRightRadius">0dp</dimen>    
</resources>
<resources>
    <!-- LEFTMOST TAB -->
    <dimen name="custom_left_tab_topLeftRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_left_tab_bottomLeftRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_left_tab_topRightRadius">0dp</dimen>
    <dimen name="custom_left_tab_bottomRightRadius">0dp</dimen>

    <!-- RIGHTMOST TAB -->
    <dimen name="custom_right_tab_topLeftRadius">0dp</dimen>
    <dimen name="custom_right_tab_bottomLeftRadius">0dp</dimen>
    <dimen name="custom_right_tab_topRightRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_right_tab_bottomRightRadius">@dimen/custom_tab_layout_radius</dimen>    
</resources>

tab_selector.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:dither="true"
    android:shape="rectangle" >

    <stroke android:width="1dp" android:color="#4c8bff"/>
    <corners android:radius="5dp" />
    <solid android:color="#FFFFFFFF" />

</shape>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true" android:drawable="@drawable/tab_selected"/>
 <!-- selected -->
    <item android:state_pressed="true" android:drawable="@drawable/tab_pressed"/>
 <!-- pressed -->
    <item android:state_focused="true" android:drawable="@drawable/tab_pressed"/>
 <!-- focused -->
    <item android:drawable="@drawable/tab_normal"/>
 <!-- default -->    
</selector>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="#4c8bff" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:dither="true"
    android:shape="rectangle" >

    <stroke
        android:width="2dp"
        android:color="@color/custom_tab_selected" />

    <corners android:radius="5dp" />

    <solid android:color="#FFFFFFFF" />

    <padding
        android:bottom="2dp"
        android:left="2dp"
        android:right="2dp"
        android:top="2dp" />

</shape>
  <dimen name="custom_tab_layout_radius">4dp</dimen>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_selected="true">
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <solid android:color="@color/custom_tab_selected" />
            <corners android:bottomLeftRadius="@dimen/custom_left_tab_bottomLeftRadius" 
                android:bottomRightRadius="@dimen/custom_left_tab_bottomRightRadius" 
                android:topLeftRadius="@dimen/custom_left_tab_topLeftRadius" 
                android:topRightRadius="@dimen/custom_left_tab_topRightRadius" />
        </shape>
    </item>
    <!-- selected -->

    <item android:state_pressed="true">
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <solid android:color="@color/custom_tab_pressed" />
            <corners android:bottomLeftRadius="@dimen/custom_left_tab_bottomLeftRadius" 
                android:bottomRightRadius="@dimen/custom_left_tab_bottomRightRadius" 
                android:topLeftRadius="@dimen/custom_left_tab_topLeftRadius" 
                android:topRightRadius="@dimen/custom_left_tab_topRightRadius" />
        </shape>
    </item>
    <!-- pressed -->

    <item android:state_focused="true">
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <solid android:color="@color/custom_tab_pressed" />
            <corners android:bottomLeftRadius="@dimen/custom_left_tab_bottomLeftRadius" 
                android:bottomRightRadius="@dimen/custom_left_tab_bottomRightRadius" 
                android:topLeftRadius="@dimen/custom_left_tab_topLeftRadius" 
                android:topRightRadius="@dimen/custom_left_tab_topRightRadius" />
        </shape>       
    </item>
    <!-- focused -->

    <item>
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <solid android:color="@color/custom_tab_normal" />
            <corners android:bottomLeftRadius="@dimen/custom_left_tab_bottomLeftRadius" 
                android:bottomRightRadius="@dimen/custom_left_tab_bottomRightRadius" 
                android:topLeftRadius="@dimen/custom_left_tab_topLeftRadius" 
                android:topRightRadius="@dimen/custom_left_tab_topRightRadius" />
        </shape>
    </item>
    <!-- default -->

</selector>
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- LEFTMOST TAB -->
    <dimen name="custom_left_tab_topLeftRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_left_tab_bottomLeftRadius">0dp</dimen>
    <dimen name="custom_left_tab_topRightRadius">0dp</dimen>
    <dimen name="custom_left_tab_bottomRightRadius">@dimen/custom_tab_layout_radius</dimen>

    <!-- RIGHTMOST TAB -->
    <dimen name="custom_right_tab_topLeftRadius">0dp</dimen>
    <dimen name="custom_right_tab_bottomLeftRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_right_tab_topRightRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_right_tab_bottomRightRadius">0dp</dimen>    
</resources>
<resources>
    <!-- LEFTMOST TAB -->
    <dimen name="custom_left_tab_topLeftRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_left_tab_bottomLeftRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_left_tab_topRightRadius">0dp</dimen>
    <dimen name="custom_left_tab_bottomRightRadius">0dp</dimen>

    <!-- RIGHTMOST TAB -->
    <dimen name="custom_right_tab_topLeftRadius">0dp</dimen>
    <dimen name="custom_right_tab_bottomLeftRadius">0dp</dimen>
    <dimen name="custom_right_tab_topRightRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_right_tab_bottomRightRadius">@dimen/custom_tab_layout_radius</dimen>    
</resources>

tab_selected.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:dither="true"
    android:shape="rectangle" >

    <stroke android:width="1dp" android:color="#4c8bff"/>
    <corners android:radius="5dp" />
    <solid android:color="#FFFFFFFF" />

</shape>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true" android:drawable="@drawable/tab_selected"/>
 <!-- selected -->
    <item android:state_pressed="true" android:drawable="@drawable/tab_pressed"/>
 <!-- pressed -->
    <item android:state_focused="true" android:drawable="@drawable/tab_pressed"/>
 <!-- focused -->
    <item android:drawable="@drawable/tab_normal"/>
 <!-- default -->    
</selector>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="#4c8bff" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:dither="true"
    android:shape="rectangle" >

    <stroke
        android:width="2dp"
        android:color="@color/custom_tab_selected" />

    <corners android:radius="5dp" />

    <solid android:color="#FFFFFFFF" />

    <padding
        android:bottom="2dp"
        android:left="2dp"
        android:right="2dp"
        android:top="2dp" />

</shape>
  <dimen name="custom_tab_layout_radius">4dp</dimen>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_selected="true">
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <solid android:color="@color/custom_tab_selected" />
            <corners android:bottomLeftRadius="@dimen/custom_left_tab_bottomLeftRadius" 
                android:bottomRightRadius="@dimen/custom_left_tab_bottomRightRadius" 
                android:topLeftRadius="@dimen/custom_left_tab_topLeftRadius" 
                android:topRightRadius="@dimen/custom_left_tab_topRightRadius" />
        </shape>
    </item>
    <!-- selected -->

    <item android:state_pressed="true">
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <solid android:color="@color/custom_tab_pressed" />
            <corners android:bottomLeftRadius="@dimen/custom_left_tab_bottomLeftRadius" 
                android:bottomRightRadius="@dimen/custom_left_tab_bottomRightRadius" 
                android:topLeftRadius="@dimen/custom_left_tab_topLeftRadius" 
                android:topRightRadius="@dimen/custom_left_tab_topRightRadius" />
        </shape>
    </item>
    <!-- pressed -->

    <item android:state_focused="true">
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <solid android:color="@color/custom_tab_pressed" />
            <corners android:bottomLeftRadius="@dimen/custom_left_tab_bottomLeftRadius" 
                android:bottomRightRadius="@dimen/custom_left_tab_bottomRightRadius" 
                android:topLeftRadius="@dimen/custom_left_tab_topLeftRadius" 
                android:topRightRadius="@dimen/custom_left_tab_topRightRadius" />
        </shape>       
    </item>
    <!-- focused -->

    <item>
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <solid android:color="@color/custom_tab_normal" />
            <corners android:bottomLeftRadius="@dimen/custom_left_tab_bottomLeftRadius" 
                android:bottomRightRadius="@dimen/custom_left_tab_bottomRightRadius" 
                android:topLeftRadius="@dimen/custom_left_tab_topLeftRadius" 
                android:topRightRadius="@dimen/custom_left_tab_topRightRadius" />
        </shape>
    </item>
    <!-- default -->

</selector>
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- LEFTMOST TAB -->
    <dimen name="custom_left_tab_topLeftRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_left_tab_bottomLeftRadius">0dp</dimen>
    <dimen name="custom_left_tab_topRightRadius">0dp</dimen>
    <dimen name="custom_left_tab_bottomRightRadius">@dimen/custom_tab_layout_radius</dimen>

    <!-- RIGHTMOST TAB -->
    <dimen name="custom_right_tab_topLeftRadius">0dp</dimen>
    <dimen name="custom_right_tab_bottomLeftRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_right_tab_topRightRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_right_tab_bottomRightRadius">0dp</dimen>    
</resources>
<resources>
    <!-- LEFTMOST TAB -->
    <dimen name="custom_left_tab_topLeftRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_left_tab_bottomLeftRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_left_tab_topRightRadius">0dp</dimen>
    <dimen name="custom_left_tab_bottomRightRadius">0dp</dimen>

    <!-- RIGHTMOST TAB -->
    <dimen name="custom_right_tab_topLeftRadius">0dp</dimen>
    <dimen name="custom_right_tab_bottomLeftRadius">0dp</dimen>
    <dimen name="custom_right_tab_topRightRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_right_tab_bottomRightRadius">@dimen/custom_tab_layout_radius</dimen>    
</resources>

更新的代码

创建选项卡\u选定\u left\u corner.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="#4c8bff" />
    <corners
       android:bottomLeftRadius="5dp"
       android:bottomRightRadius="0dp"
       android:topLeftRadius="5dp"
       android:topRightRadius="0dp" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="#4c8bff" />
    <corners
        android:bottomLeftRadius="0dp"
        android:bottomRightRadius="5dp"
        android:topLeftRadius="0dp"
        android:topRightRadius="5dp" />
</shape>

这对我有用。。希望你也能这样。

@Sulabh Gajjar-非常感谢你给出如此详细的答案。我考虑过这个方法,但我想知道是否有更好的方法,所以把它作为我最后的选择。 正如您所建议的,为左侧和右侧选项卡创建了2个选择器,而不是创建新的可绘制图形,我在选择器本身中编写了形状,并创建了2个单独的文件来存储不同的角半径,如所建议的。目前它对我有效,但我会再等几天,万一有人想出一个更通用的方法,如果没有人出现,我会把你的答案标记为接受。再次感谢……:)

使用您的方法,下面是我为使其运行所做的

布局


自定义选项卡\u background.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:dither="true"
    android:shape="rectangle" >

    <stroke android:width="1dp" android:color="#4c8bff"/>
    <corners android:radius="5dp" />
    <solid android:color="#FFFFFFFF" />

</shape>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true" android:drawable="@drawable/tab_selected"/>
 <!-- selected -->
    <item android:state_pressed="true" android:drawable="@drawable/tab_pressed"/>
 <!-- pressed -->
    <item android:state_focused="true" android:drawable="@drawable/tab_pressed"/>
 <!-- focused -->
    <item android:drawable="@drawable/tab_normal"/>
 <!-- default -->    
</selector>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="#4c8bff" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:dither="true"
    android:shape="rectangle" >

    <stroke
        android:width="2dp"
        android:color="@color/custom_tab_selected" />

    <corners android:radius="5dp" />

    <solid android:color="#FFFFFFFF" />

    <padding
        android:bottom="2dp"
        android:left="2dp"
        android:right="2dp"
        android:top="2dp" />

</shape>
  <dimen name="custom_tab_layout_radius">4dp</dimen>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_selected="true">
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <solid android:color="@color/custom_tab_selected" />
            <corners android:bottomLeftRadius="@dimen/custom_left_tab_bottomLeftRadius" 
                android:bottomRightRadius="@dimen/custom_left_tab_bottomRightRadius" 
                android:topLeftRadius="@dimen/custom_left_tab_topLeftRadius" 
                android:topRightRadius="@dimen/custom_left_tab_topRightRadius" />
        </shape>
    </item>
    <!-- selected -->

    <item android:state_pressed="true">
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <solid android:color="@color/custom_tab_pressed" />
            <corners android:bottomLeftRadius="@dimen/custom_left_tab_bottomLeftRadius" 
                android:bottomRightRadius="@dimen/custom_left_tab_bottomRightRadius" 
                android:topLeftRadius="@dimen/custom_left_tab_topLeftRadius" 
                android:topRightRadius="@dimen/custom_left_tab_topRightRadius" />
        </shape>
    </item>
    <!-- pressed -->

    <item android:state_focused="true">
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <solid android:color="@color/custom_tab_pressed" />
            <corners android:bottomLeftRadius="@dimen/custom_left_tab_bottomLeftRadius" 
                android:bottomRightRadius="@dimen/custom_left_tab_bottomRightRadius" 
                android:topLeftRadius="@dimen/custom_left_tab_topLeftRadius" 
                android:topRightRadius="@dimen/custom_left_tab_topRightRadius" />
        </shape>       
    </item>
    <!-- focused -->

    <item>
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <solid android:color="@color/custom_tab_normal" />
            <corners android:bottomLeftRadius="@dimen/custom_left_tab_bottomLeftRadius" 
                android:bottomRightRadius="@dimen/custom_left_tab_bottomRightRadius" 
                android:topLeftRadius="@dimen/custom_left_tab_topLeftRadius" 
                android:topRightRadius="@dimen/custom_left_tab_topRightRadius" />
        </shape>
    </item>
    <!-- default -->

</selector>
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- LEFTMOST TAB -->
    <dimen name="custom_left_tab_topLeftRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_left_tab_bottomLeftRadius">0dp</dimen>
    <dimen name="custom_left_tab_topRightRadius">0dp</dimen>
    <dimen name="custom_left_tab_bottomRightRadius">@dimen/custom_tab_layout_radius</dimen>

    <!-- RIGHTMOST TAB -->
    <dimen name="custom_right_tab_topLeftRadius">0dp</dimen>
    <dimen name="custom_right_tab_bottomLeftRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_right_tab_topRightRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_right_tab_bottomRightRadius">0dp</dimen>    
</resources>
<resources>
    <!-- LEFTMOST TAB -->
    <dimen name="custom_left_tab_topLeftRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_left_tab_bottomLeftRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_left_tab_topRightRadius">0dp</dimen>
    <dimen name="custom_left_tab_bottomRightRadius">0dp</dimen>

    <!-- RIGHTMOST TAB -->
    <dimen name="custom_right_tab_topLeftRadius">0dp</dimen>
    <dimen name="custom_right_tab_bottomLeftRadius">0dp</dimen>
    <dimen name="custom_right_tab_topRightRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_right_tab_bottomRightRadius">@dimen/custom_tab_layout_radius</dimen>    
</resources>

dimens.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:dither="true"
    android:shape="rectangle" >

    <stroke android:width="1dp" android:color="#4c8bff"/>
    <corners android:radius="5dp" />
    <solid android:color="#FFFFFFFF" />

</shape>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true" android:drawable="@drawable/tab_selected"/>
 <!-- selected -->
    <item android:state_pressed="true" android:drawable="@drawable/tab_pressed"/>
 <!-- pressed -->
    <item android:state_focused="true" android:drawable="@drawable/tab_pressed"/>
 <!-- focused -->
    <item android:drawable="@drawable/tab_normal"/>
 <!-- default -->    
</selector>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="#4c8bff" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:dither="true"
    android:shape="rectangle" >

    <stroke
        android:width="2dp"
        android:color="@color/custom_tab_selected" />

    <corners android:radius="5dp" />

    <solid android:color="#FFFFFFFF" />

    <padding
        android:bottom="2dp"
        android:left="2dp"
        android:right="2dp"
        android:top="2dp" />

</shape>
  <dimen name="custom_tab_layout_radius">4dp</dimen>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_selected="true">
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <solid android:color="@color/custom_tab_selected" />
            <corners android:bottomLeftRadius="@dimen/custom_left_tab_bottomLeftRadius" 
                android:bottomRightRadius="@dimen/custom_left_tab_bottomRightRadius" 
                android:topLeftRadius="@dimen/custom_left_tab_topLeftRadius" 
                android:topRightRadius="@dimen/custom_left_tab_topRightRadius" />
        </shape>
    </item>
    <!-- selected -->

    <item android:state_pressed="true">
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <solid android:color="@color/custom_tab_pressed" />
            <corners android:bottomLeftRadius="@dimen/custom_left_tab_bottomLeftRadius" 
                android:bottomRightRadius="@dimen/custom_left_tab_bottomRightRadius" 
                android:topLeftRadius="@dimen/custom_left_tab_topLeftRadius" 
                android:topRightRadius="@dimen/custom_left_tab_topRightRadius" />
        </shape>
    </item>
    <!-- pressed -->

    <item android:state_focused="true">
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <solid android:color="@color/custom_tab_pressed" />
            <corners android:bottomLeftRadius="@dimen/custom_left_tab_bottomLeftRadius" 
                android:bottomRightRadius="@dimen/custom_left_tab_bottomRightRadius" 
                android:topLeftRadius="@dimen/custom_left_tab_topLeftRadius" 
                android:topRightRadius="@dimen/custom_left_tab_topRightRadius" />
        </shape>       
    </item>
    <!-- focused -->

    <item>
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <solid android:color="@color/custom_tab_normal" />
            <corners android:bottomLeftRadius="@dimen/custom_left_tab_bottomLeftRadius" 
                android:bottomRightRadius="@dimen/custom_left_tab_bottomRightRadius" 
                android:topLeftRadius="@dimen/custom_left_tab_topLeftRadius" 
                android:topRightRadius="@dimen/custom_left_tab_topRightRadius" />
        </shape>
    </item>
    <!-- default -->

</selector>
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- LEFTMOST TAB -->
    <dimen name="custom_left_tab_topLeftRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_left_tab_bottomLeftRadius">0dp</dimen>
    <dimen name="custom_left_tab_topRightRadius">0dp</dimen>
    <dimen name="custom_left_tab_bottomRightRadius">@dimen/custom_tab_layout_radius</dimen>

    <!-- RIGHTMOST TAB -->
    <dimen name="custom_right_tab_topLeftRadius">0dp</dimen>
    <dimen name="custom_right_tab_bottomLeftRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_right_tab_topRightRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_right_tab_bottomRightRadius">0dp</dimen>    
</resources>
<resources>
    <!-- LEFTMOST TAB -->
    <dimen name="custom_left_tab_topLeftRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_left_tab_bottomLeftRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_left_tab_topRightRadius">0dp</dimen>
    <dimen name="custom_left_tab_bottomRightRadius">0dp</dimen>

    <!-- RIGHTMOST TAB -->
    <dimen name="custom_right_tab_topLeftRadius">0dp</dimen>
    <dimen name="custom_right_tab_bottomLeftRadius">0dp</dimen>
    <dimen name="custom_right_tab_topRightRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_right_tab_bottomRightRadius">@dimen/custom_tab_layout_radius</dimen>    
</resources>
4dp
自定义选项卡选择器\u left.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:dither="true"
    android:shape="rectangle" >

    <stroke android:width="1dp" android:color="#4c8bff"/>
    <corners android:radius="5dp" />
    <solid android:color="#FFFFFFFF" />

</shape>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true" android:drawable="@drawable/tab_selected"/>
 <!-- selected -->
    <item android:state_pressed="true" android:drawable="@drawable/tab_pressed"/>
 <!-- pressed -->
    <item android:state_focused="true" android:drawable="@drawable/tab_pressed"/>
 <!-- focused -->
    <item android:drawable="@drawable/tab_normal"/>
 <!-- default -->    
</selector>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="#4c8bff" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:dither="true"
    android:shape="rectangle" >

    <stroke
        android:width="2dp"
        android:color="@color/custom_tab_selected" />

    <corners android:radius="5dp" />

    <solid android:color="#FFFFFFFF" />

    <padding
        android:bottom="2dp"
        android:left="2dp"
        android:right="2dp"
        android:top="2dp" />

</shape>
  <dimen name="custom_tab_layout_radius">4dp</dimen>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_selected="true">
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <solid android:color="@color/custom_tab_selected" />
            <corners android:bottomLeftRadius="@dimen/custom_left_tab_bottomLeftRadius" 
                android:bottomRightRadius="@dimen/custom_left_tab_bottomRightRadius" 
                android:topLeftRadius="@dimen/custom_left_tab_topLeftRadius" 
                android:topRightRadius="@dimen/custom_left_tab_topRightRadius" />
        </shape>
    </item>
    <!-- selected -->

    <item android:state_pressed="true">
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <solid android:color="@color/custom_tab_pressed" />
            <corners android:bottomLeftRadius="@dimen/custom_left_tab_bottomLeftRadius" 
                android:bottomRightRadius="@dimen/custom_left_tab_bottomRightRadius" 
                android:topLeftRadius="@dimen/custom_left_tab_topLeftRadius" 
                android:topRightRadius="@dimen/custom_left_tab_topRightRadius" />
        </shape>
    </item>
    <!-- pressed -->

    <item android:state_focused="true">
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <solid android:color="@color/custom_tab_pressed" />
            <corners android:bottomLeftRadius="@dimen/custom_left_tab_bottomLeftRadius" 
                android:bottomRightRadius="@dimen/custom_left_tab_bottomRightRadius" 
                android:topLeftRadius="@dimen/custom_left_tab_topLeftRadius" 
                android:topRightRadius="@dimen/custom_left_tab_topRightRadius" />
        </shape>       
    </item>
    <!-- focused -->

    <item>
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <solid android:color="@color/custom_tab_normal" />
            <corners android:bottomLeftRadius="@dimen/custom_left_tab_bottomLeftRadius" 
                android:bottomRightRadius="@dimen/custom_left_tab_bottomRightRadius" 
                android:topLeftRadius="@dimen/custom_left_tab_topLeftRadius" 
                android:topRightRadius="@dimen/custom_left_tab_topRightRadius" />
        </shape>
    </item>
    <!-- default -->

</selector>
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- LEFTMOST TAB -->
    <dimen name="custom_left_tab_topLeftRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_left_tab_bottomLeftRadius">0dp</dimen>
    <dimen name="custom_left_tab_topRightRadius">0dp</dimen>
    <dimen name="custom_left_tab_bottomRightRadius">@dimen/custom_tab_layout_radius</dimen>

    <!-- RIGHTMOST TAB -->
    <dimen name="custom_right_tab_topLeftRadius">0dp</dimen>
    <dimen name="custom_right_tab_bottomLeftRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_right_tab_topRightRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_right_tab_bottomRightRadius">0dp</dimen>    
</resources>
<resources>
    <!-- LEFTMOST TAB -->
    <dimen name="custom_left_tab_topLeftRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_left_tab_bottomLeftRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_left_tab_topRightRadius">0dp</dimen>
    <dimen name="custom_left_tab_bottomRightRadius">0dp</dimen>

    <!-- RIGHTMOST TAB -->
    <dimen name="custom_right_tab_topLeftRadius">0dp</dimen>
    <dimen name="custom_right_tab_bottomLeftRadius">0dp</dimen>
    <dimen name="custom_right_tab_topRightRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_right_tab_bottomRightRadius">@dimen/custom_tab_layout_radius</dimen>    
</resources>

/res/values/custom_tab_corners.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:dither="true"
    android:shape="rectangle" >

    <stroke android:width="1dp" android:color="#4c8bff"/>
    <corners android:radius="5dp" />
    <solid android:color="#FFFFFFFF" />

</shape>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true" android:drawable="@drawable/tab_selected"/>
 <!-- selected -->
    <item android:state_pressed="true" android:drawable="@drawable/tab_pressed"/>
 <!-- pressed -->
    <item android:state_focused="true" android:drawable="@drawable/tab_pressed"/>
 <!-- focused -->
    <item android:drawable="@drawable/tab_normal"/>
 <!-- default -->    
</selector>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="#4c8bff" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:dither="true"
    android:shape="rectangle" >

    <stroke
        android:width="2dp"
        android:color="@color/custom_tab_selected" />

    <corners android:radius="5dp" />

    <solid android:color="#FFFFFFFF" />

    <padding
        android:bottom="2dp"
        android:left="2dp"
        android:right="2dp"
        android:top="2dp" />

</shape>
  <dimen name="custom_tab_layout_radius">4dp</dimen>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_selected="true">
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <solid android:color="@color/custom_tab_selected" />
            <corners android:bottomLeftRadius="@dimen/custom_left_tab_bottomLeftRadius" 
                android:bottomRightRadius="@dimen/custom_left_tab_bottomRightRadius" 
                android:topLeftRadius="@dimen/custom_left_tab_topLeftRadius" 
                android:topRightRadius="@dimen/custom_left_tab_topRightRadius" />
        </shape>
    </item>
    <!-- selected -->

    <item android:state_pressed="true">
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <solid android:color="@color/custom_tab_pressed" />
            <corners android:bottomLeftRadius="@dimen/custom_left_tab_bottomLeftRadius" 
                android:bottomRightRadius="@dimen/custom_left_tab_bottomRightRadius" 
                android:topLeftRadius="@dimen/custom_left_tab_topLeftRadius" 
                android:topRightRadius="@dimen/custom_left_tab_topRightRadius" />
        </shape>
    </item>
    <!-- pressed -->

    <item android:state_focused="true">
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <solid android:color="@color/custom_tab_pressed" />
            <corners android:bottomLeftRadius="@dimen/custom_left_tab_bottomLeftRadius" 
                android:bottomRightRadius="@dimen/custom_left_tab_bottomRightRadius" 
                android:topLeftRadius="@dimen/custom_left_tab_topLeftRadius" 
                android:topRightRadius="@dimen/custom_left_tab_topRightRadius" />
        </shape>       
    </item>
    <!-- focused -->

    <item>
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <solid android:color="@color/custom_tab_normal" />
            <corners android:bottomLeftRadius="@dimen/custom_left_tab_bottomLeftRadius" 
                android:bottomRightRadius="@dimen/custom_left_tab_bottomRightRadius" 
                android:topLeftRadius="@dimen/custom_left_tab_topLeftRadius" 
                android:topRightRadius="@dimen/custom_left_tab_topRightRadius" />
        </shape>
    </item>
    <!-- default -->

</selector>
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- LEFTMOST TAB -->
    <dimen name="custom_left_tab_topLeftRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_left_tab_bottomLeftRadius">0dp</dimen>
    <dimen name="custom_left_tab_topRightRadius">0dp</dimen>
    <dimen name="custom_left_tab_bottomRightRadius">@dimen/custom_tab_layout_radius</dimen>

    <!-- RIGHTMOST TAB -->
    <dimen name="custom_right_tab_topLeftRadius">0dp</dimen>
    <dimen name="custom_right_tab_bottomLeftRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_right_tab_topRightRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_right_tab_bottomRightRadius">0dp</dimen>    
</resources>
<resources>
    <!-- LEFTMOST TAB -->
    <dimen name="custom_left_tab_topLeftRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_left_tab_bottomLeftRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_left_tab_topRightRadius">0dp</dimen>
    <dimen name="custom_left_tab_bottomRightRadius">0dp</dimen>

    <!-- RIGHTMOST TAB -->
    <dimen name="custom_right_tab_topLeftRadius">0dp</dimen>
    <dimen name="custom_right_tab_bottomLeftRadius">0dp</dimen>
    <dimen name="custom_right_tab_topRightRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_right_tab_bottomRightRadius">@dimen/custom_tab_layout_radius</dimen>    
</resources>

@尺寸/自定义选项卡布局半径
0dp
0dp
@尺寸/自定义选项卡布局半径
0dp
@尺寸/自定义选项卡布局半径
@尺寸/自定义选项卡布局半径
0dp
/res/values-v12/custom\u tab\u corners.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:dither="true"
    android:shape="rectangle" >

    <stroke android:width="1dp" android:color="#4c8bff"/>
    <corners android:radius="5dp" />
    <solid android:color="#FFFFFFFF" />

</shape>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true" android:drawable="@drawable/tab_selected"/>
 <!-- selected -->
    <item android:state_pressed="true" android:drawable="@drawable/tab_pressed"/>
 <!-- pressed -->
    <item android:state_focused="true" android:drawable="@drawable/tab_pressed"/>
 <!-- focused -->
    <item android:drawable="@drawable/tab_normal"/>
 <!-- default -->    
</selector>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="#4c8bff" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:dither="true"
    android:shape="rectangle" >

    <stroke
        android:width="2dp"
        android:color="@color/custom_tab_selected" />

    <corners android:radius="5dp" />

    <solid android:color="#FFFFFFFF" />

    <padding
        android:bottom="2dp"
        android:left="2dp"
        android:right="2dp"
        android:top="2dp" />

</shape>
  <dimen name="custom_tab_layout_radius">4dp</dimen>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_selected="true">
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <solid android:color="@color/custom_tab_selected" />
            <corners android:bottomLeftRadius="@dimen/custom_left_tab_bottomLeftRadius" 
                android:bottomRightRadius="@dimen/custom_left_tab_bottomRightRadius" 
                android:topLeftRadius="@dimen/custom_left_tab_topLeftRadius" 
                android:topRightRadius="@dimen/custom_left_tab_topRightRadius" />
        </shape>
    </item>
    <!-- selected -->

    <item android:state_pressed="true">
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <solid android:color="@color/custom_tab_pressed" />
            <corners android:bottomLeftRadius="@dimen/custom_left_tab_bottomLeftRadius" 
                android:bottomRightRadius="@dimen/custom_left_tab_bottomRightRadius" 
                android:topLeftRadius="@dimen/custom_left_tab_topLeftRadius" 
                android:topRightRadius="@dimen/custom_left_tab_topRightRadius" />
        </shape>
    </item>
    <!-- pressed -->

    <item android:state_focused="true">
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <solid android:color="@color/custom_tab_pressed" />
            <corners android:bottomLeftRadius="@dimen/custom_left_tab_bottomLeftRadius" 
                android:bottomRightRadius="@dimen/custom_left_tab_bottomRightRadius" 
                android:topLeftRadius="@dimen/custom_left_tab_topLeftRadius" 
                android:topRightRadius="@dimen/custom_left_tab_topRightRadius" />
        </shape>       
    </item>
    <!-- focused -->

    <item>
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <solid android:color="@color/custom_tab_normal" />
            <corners android:bottomLeftRadius="@dimen/custom_left_tab_bottomLeftRadius" 
                android:bottomRightRadius="@dimen/custom_left_tab_bottomRightRadius" 
                android:topLeftRadius="@dimen/custom_left_tab_topLeftRadius" 
                android:topRightRadius="@dimen/custom_left_tab_topRightRadius" />
        </shape>
    </item>
    <!-- default -->

</selector>
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- LEFTMOST TAB -->
    <dimen name="custom_left_tab_topLeftRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_left_tab_bottomLeftRadius">0dp</dimen>
    <dimen name="custom_left_tab_topRightRadius">0dp</dimen>
    <dimen name="custom_left_tab_bottomRightRadius">@dimen/custom_tab_layout_radius</dimen>

    <!-- RIGHTMOST TAB -->
    <dimen name="custom_right_tab_topLeftRadius">0dp</dimen>
    <dimen name="custom_right_tab_bottomLeftRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_right_tab_topRightRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_right_tab_bottomRightRadius">0dp</dimen>    
</resources>
<resources>
    <!-- LEFTMOST TAB -->
    <dimen name="custom_left_tab_topLeftRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_left_tab_bottomLeftRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_left_tab_topRightRadius">0dp</dimen>
    <dimen name="custom_left_tab_bottomRightRadius">0dp</dimen>

    <!-- RIGHTMOST TAB -->
    <dimen name="custom_right_tab_topLeftRadius">0dp</dimen>
    <dimen name="custom_right_tab_bottomLeftRadius">0dp</dimen>
    <dimen name="custom_right_tab_topRightRadius">@dimen/custom_tab_layout_radius</dimen>
    <dimen name="custom_right_tab_bottomRightRadius">@dimen/custom_tab_layout_radius</dimen>    
</resources>

@尺寸/自定义选项卡布局半径
@尺寸/自定义选项卡布局半径
0dp
0dp
0dp
0dp
@尺寸/自定义选项卡布局半径
@尺寸/自定义选项卡布局半径

你能发布你得到的输出图像吗?它做的事情是一样的,只是它在textview的四个角上做了取整,这看起来很糟糕,靠近布局中心的分隔线,加上未选中的选项卡由于重叠而没有得到边框