2012-01-08 40 views
2

複選框文本不上取向的變化而變化複選框文本不會更改的取向變化

我有不同的佈局文件(一個在佈局和一個佈局,土地)的屏幕,唯一的區別是,一些UI文件中的小部件指向不同的字符串(橫向模式的較長字符串)。對於TextView小部件,將顯示正確的資源字符串,但對於CheckBox,顯示的文本在所有方向更改期間保持不變。

./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> 

因此,與上述上label1Short和label1Long之間的方位變化label1的文本改變。但checkBox1的文本與第一次查看屏幕時設備方向正確的文本保持一致。

有什麼想法?謝謝 邁克

回答

2

即使配置更改(方向更改您的情況下),CheckBox小部件保存它的狀態。作爲你的問題的解決方案,你可以自己定義Activity的onConfigurationChange方法。