方向更改时复选框文本不会更改
复选框文本在方向更改时不会更改
我的屏幕有不同的布局文件(一个在布局中,一个在布局区域中),唯一的区别是文件中的某些 UI 小部件指向不同的字符串(横向模式的字符串较长) 。对于 TextView 小部件,将显示正确的资源字符串,但对于复选框,显示的文本在所有方向更改期间保持不变。
./layout/tabA.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/label1"
style="@style/TextBoxLabel.Header.WithInputsOnScreen"
android:text="@string/label1Short"
/>
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:layout_below="@id/label1"
android:text="@string/checkBox1Short"
/>
</RelativeLayout>
</ScrollView>
./layout-land/tabA.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/label1"
style="@style/TextBoxLabel.Header.WithInputsOnScreen"
android:text="@string/label1Long"
/>
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:layout_below="@id/label1"
android:text="@string/checkBox1Long"
/>
</RelativeLayout>
</ScrollView>
因此,根据上面的内容,在方向更改时,label1 的文本在 label1Short 和 label1Long 之间更改。但 checkBox1 的文本与首次查看屏幕时针对设备方向正确的文本保持相同。
有什么想法吗?谢谢 麦克风
CheckBox Text Does Not Change on Orientation Change
I have differing layout files (one in layout and one in layout-land) for a screen with the only difference being that some UI widgets in the files point to different string (longer string for landscape mode). For TextView widgets the correct resource Strings are displayed, but for CheckBoxes the text displayed stays the same during all orientation changes.
./layout/tabA.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/label1"
style="@style/TextBoxLabel.Header.WithInputsOnScreen"
android:text="@string/label1Short"
/>
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:layout_below="@id/label1"
android:text="@string/checkBox1Short"
/>
</RelativeLayout>
</ScrollView>
./layout-land/tabA.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/label1"
style="@style/TextBoxLabel.Header.WithInputsOnScreen"
android:text="@string/label1Long"
/>
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:layout_below="@id/label1"
android:text="@string/checkBox1Long"
/>
</RelativeLayout>
</ScrollView>
So with the above, on an orientation change label1's text changes between label1Short and label1Long. But checkBox1's text stays the same as the text that was correct for the device orientation when the screen was first viewed.
Any thoughts? Thanks
Mike
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
即使配置更改(在您的情况下方向更改),复选框小部件也会保存其状态。作为问题的解决方案,您可以自己定义 Activity 的 onConfigurationChange 方法。
CheckBox widget save it state even after configuration change (orientation change in your case). As solution of your problem you can define Activity's onConfigurationChange method by yourself.