我正在尝试在ListView中使用R.layout.simple_list_item_multiple_choice。simple_list_item_multiple_choice.xml中使用了CheckedTextView,但是如何使复选框左对齐而不是右对齐?
发布于 2015-08-17 20:37:43
你可以把你的drawable赋值给drawableLeft属性,但是这对你没有任何好处,因为它不支持着色。相反,我像这样扩展了CheckedTextView:
public class LeftSideCheckedTextView extends CheckedTextView {
public LeftSideCheckedTextView(Context context) {
this(context, null, 0);
}
public LeftSideCheckedTextView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public LeftSideCheckedTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
Field mCheckMarkGravity = null;
try {
mCheckMarkGravity = this.getClass().getSuperclass().getDeclaredField("mCheckMarkGravity");
mCheckMarkGravity.setAccessible(true);
mCheckMarkGravity.set(this, Gravity.START);
} catch (Exception e) {
Logger.error(e);
}
}
}
在这里,我访问了隐藏字段mCheckMarkGravity,该字段在CheckedTextView中使用,但无法通过样式属性进行访问,根据这个错误标签:https://code.google.com/p/android/issues/detail?id=174517
https://stackoverflow.com/questions/3114745
复制相似问题