android - 9patch drawable 1px 黑线可见&内容定位

标签 android android-layout

我得到了 9patch,感谢回答我上一个问题的好心人: enter image description here

我将它用于相对布局和 TextView 的背景,并得到了关注。 那是 RelativeLayout 的:

  <RelativeLayout
        android:id="@+id/relativeHeader"
        android:layout_width="fill_parent"
        android:layout_height="60dp"
        android:orientation="horizontal"
        android: background="@drawable/cap_stack">

enter image description here

对于 TextView:

<TextView
       android:paddingTop="5dp"
       android:gravity="center_vertical"
       android:layout_width="fill_parent"
       android:layout_height="22dp"
       android:background="@drawable/cap_stack"
       android:textStyle="bold"
       android:textColor="#FFFFFF"/>

enter image description here

如您所见,在这两种情况下我都看到了 1px 宽的线条。在 TextView 的情况下,文本不会放置在垂直中心。我该如何修复它(是可绘制问题还是 xml)?将不胜感激任何帮助

最佳答案

您不应该一直使用实线边框。顶部和左侧边界定义了拉伸(stretch)区域(您只需要顶部的一个像素用于拉伸(stretch),并且您只想让渐变在垂直轴上拉伸(stretch))。底部和右侧边框定义了内容区域,因此您也想保留一些填充。永远不要填充四个角像素。

试试这个:

enter image description here

或者这个:

enter image description here

关于android - 9patch drawable 1px 黑线可见&内容定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6178907/

相关文章:

android - Android fragment 之间的阴影分隔符

android - 如何使用自定义布局作为 RadioButton 标签

android - onKeyDown() 问题

java - 使用 GSON 加载非常重的流

android - 如何更改android studio中的默认布局(activity_main)

android - Android 中的完全自定义对话框

java - 在将布局膨胀对象添加到 View 时设置其重力

android - 检查音乐是否在 android 媒体播放器 API 中播放

Android map 无法在 CollapsingToolbarLayout 中正确滚动

java - Android Canvas.DrawBitmap 没有模糊/抗锯齿?