【问题标题】:android, checkedTextView: checkmarks of different widthandroid,checkedTextView:不同宽度的复选标记
【发布时间】:2013-01-16 18:30:26
【问题描述】:

我有 CheckedTextView 选择器:

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@drawable/checkbox_checked" android:state_checked="true"/>
<item android:drawable="@drawable/checkbox_unchecked" android:state_checked="false"/>

</selector>

当我有 2 个这样的选中文本视图时,第一个未选中,另一个已选中,看起来像这样:

您可以注意到,与选中状态相比,未选中状态下的边框更宽。根据我的资源,这些边框的宽度相同,但由于绘制橙色复选标记需要额外的像素,因此选中的资源更宽。

如何让边框看起来一样?有没有比使用RelativeLayout + TextView + Checkbox 更有效的方法?


更新 1,布局:

    <CheckedTextView
        android:id="@+id/saveVideoOnServer"
        style="@style/talCell.textView.checked"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/saveVideoOnServer" />
        android:background="@android:color/transparent"

    <CheckedTextView
        android:id="@+id/showMyPosition"
        style="@style/talCell.textView.checked"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:checked="true"
        android:text="@string/showMyPosition" />

它们在垂直线性布局内。我没有发布整个布局,因为它有 100 多行。

【问题讨论】:

  • 您可以发布布局文件(带有CheckBox)吗?那些是九个补丁的图像吗?
  • 已添加。这些是通常的 png,而不是 9-patch。

标签: android checkedtextview


【解决方案1】:

您需要使两个图像的宽度相同。在您提到的问题中,边框的宽度相同。如果您现在只是通过添加透明像素来使未检查的图像更宽,那么一切都应该有效。

总结一下:您需要两张相同尺寸、相同尺寸和相同位置边框的图像。

Android 源代码也是如此,请查看以下两个复选框图像:它们具有相同的大小(在 github 站点上更容易看到:not checkedchecked

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-09
    • 2020-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-22
    相关资源
    最近更新 更多