我有 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 个这样的选中 TextView 一个在另一个下面时,第一个未选中,另一个被选中,它看起来像这样:
您可以注意到,与选中状态相比,未选中状态的边框更宽。根据我的资源,这些边框的宽度相同,但由于绘制橙色复选标记需要额外的像素,因此选中的资源更宽。
如何让边框看起来一样?有没有比使用 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 多行。
最佳答案
您需要使两个图像的宽度相同。在您提到的问题中,边框的宽度相同。如果您现在通过添加透明像素简单地使未检查的图像变宽,一切都应该有效。
总而言之:您需要两张具有相同大小和相同位置边框的相同大小的图像。
Android Source 做同样的事情,看看下面两个复选框图像:它们具有相同的大小(在 github 站点上更容易看到:not checked,checked)
关于机器人,checkedTextView : checkmarks of different width,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14337911/