在父布局上设置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设置为默认值(clipBounds),右边的设置为。
9补丁PNG也附在这个职位上.
这个案子的正确行为是什么?

9-正在使用的贴片图像:

更新9-每个评注的贴片图像建议:

用SDK的正式文件更新
使用SDL (samples/android-20/legacy/ApiDemos/res/drawable-mdpi/btn_default_normal.9.png)中的9补丁映像,结果如下所示:

SDK文件(由我添加的用于光学边界的红色标记):

问题仍然存在,内容领域没有得到考虑,文本不应跨越边界。
发布于 2014-08-11 09:20:44
移除的android:padding="0dp"和填充是正确的。
https://stackoverflow.com/questions/25238989
复制相似问题