I am using a Fragment class in a TabHost. This fragment inflates a KeyboardView like this:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (container == null)
return null;
View v = inflater.inflate(R.layout.main_keyboard, container, false);
This works fine the first time onCreateView()
is invoked (when the application loads). However, subsequent screen rotates (runtime configuration changes) don't re-size the KeyboardView to landscape/portrait properly:
main_keyboard.xml You can see the KeyboardView being referenced at the bottom: `
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="10dip" >
<TextView
android:id="@+id/kbd_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="10dip"
android:text="@string/keyboard_type" />
<TextView
android:id="@+id/kbd_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/kbd_header"
android:text="@string/russian"
android:textColor="#FF0000"
android:textStyle="bold" />
</RelativeLayout>
<ImageButton
android:id="@+id/btnRussian"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dip"
android:contentDescription="@string/russian_keyboard"
android:src="@drawable/russia" />
<ImageButton
android:id="@+id/btnEnglish"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dip"
android:contentDescription="@string/english_keyboard"
android:src="@drawable/america"
/>
<ImageButton
android:id="@+id/btnCombined"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/combined"
android:src="@drawable/combined" />
</LinearLayout>
<com.eazyigz.RussiaMediaSearch.CustomKeyboardView
android:id="@+id/keyboard_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="0px"
android:padding="0px" >
</com.eazyigz.RussiaMediaSearch.CustomKeyboardView>
Does anybody have ideas on how to make the KeyboardView resize correctly?
Thank you, Igor
Problem solved: I was using: if (savedInstanceState != null)
in onCreateView , and wasn't creating a new Keyboard object every time the screen rotated. So that's why the keyboard didn't resize. To resolve this, I needed to run code like this every time:
mKeyboard = new Keyboard(getActivity(), R.xml.keyboard);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.