似乎在父布局上设置layoutMode =“ opticalBounds”将禁用9-Patch内容区域。下面的屏幕截图是一个简单的TextView:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:orientation="vertical"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:paddingLeft="20dp"
             android:paddingTop="20dp">

    <TextView
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:background="@drawable/shadow_with_stroke_gray"
        android:text="lorem ipsum etc"
        android:padding="0dp"
        />
</FrameLayout>


而左边的FrameLayout的layoutMode设置为default(clipBounds),右边的frameLayout设置为OpticalBounds。

此帖子还附带了9个补丁的PNG。

在这种情况下正确的行为是什么?



正在使用9补丁图像:



每个评论者建议的更新的9补丁图像:



使用SDK中的官方文件进行了更新

使用SDL中的9个补丁图像(samples / android-20 / legacy / ApiDemos / res / drawable-mdpi / btn_default_normal.9.png),结果如下所示:



SDK文件(我添加的用于光学范围的红色标记):



问题仍然存在,没有考虑内容区域,文本不应越过边界。

最佳答案

删除android:padding="0dp"并且填充正确。

10-07 19:35
查看更多