请注意,相同的代码在Android上运行得非常好 版本>奇巧
我对调查问卷有一个动态的看法。所有观点都是根据我正在使用的api提出的问题添加的。我想要做的是,如果问题是必需的,但用户没有填写它并尝试提交它,我试图将“可见性”设置为“VISIBLE”到我的TextView,文本“必需”
当我处于横向或纵向模式时,它完全正常,但在更改方向后,它会停止工作。
我调试了代码并进行了检查,可见性状态正在更改,但UI未更新。
除了KITKAT之外它工作得很好
我试过view.invalidate();同样。
将TextView布局设置为VISIBLE
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/required_prompt_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.goodsnitch.lib.ui.LatoRegularTextView
android:id="@+id/required_prompt_dynamic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/field_required_prompt"
android:textColor="@android:color/holo_red_light"
android:textSize="11dp"
android:textStyle="italic"
android:visibility="gone" />
</LinearLayout>
使其可见的Java代码
private void showRequiredPrompt(final View view) {
final TextView requiredLabel = (TextView) ((LinearLayout) view.getParent()).findViewById(R.id.required_prompt_dynamic);
if (requiredLabel != null) {
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
view.clearAnimation();
requiredLabel.clearAnimation();
requiredLabel.setVisibility(View.VISIBLE);
view.invalidate();
requiredLabel.invalidate();
}
}, 200);
}
}
我将非常感谢你的帮助:)。
编辑问题以进一步解释
This is code to show the label ON CLICK EVENT This is the toast showing visibility state of the label
所需标签应出现在RED颜色的第一个复选框上方
答案 0 :(得分:0)
当你使用屏幕旋转时,使用onSaveInstanceState()和onRestoreInstanceState()。