我面临以下问题 - 下载我的新太空模拟游戏的人(但不是所有人)都在抱怨,他们在他们的设备上看不到任何控件。该问题似乎仅存在于 S3 设备上。我自己和 S3 在一起,一切都按设计显示。
这些控件被实现为自定义单选按钮,我将在下面发布代码,但是我的问题是:什么可能导致这种不同的行为?
public class CenteredRadioButton extends RadioButton {
private Drawable buttonDrawable;
public CenteredRadioButton(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CompoundButton, 0, 0);
buttonDrawable = a.getDrawable(1);
setButtonDrawable(R.drawable.radio_empty);
}
public void setCustomDrawable(Drawable drawable) {
buttonDrawable = drawable;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (buttonDrawable != null) {
buttonDrawable.setState(getDrawableState());
final int verticalGravity = getGravity() & Gravity.VERTICAL_GRAVITY_MASK;
final int height = buttonDrawable.getIntrinsicHeight();
int y = 0;
switch (verticalGravity) {
case (Gravity.BOTTOM) : {
y = getHeight() - height;
break;
} case (Gravity.CENTER_VERTICAL) : {
y = (getHeight() - height) / 2;
break;
}
}
int buttonWidth = buttonDrawable.getIntrinsicWidth();
int buttonLeft = (getWidth() - buttonWidth) / 2;
buttonDrawable.setBounds(buttonLeft, y, buttonLeft + buttonWidth, y + height);
buttonDrawable.draw(canvas);
}
}
}