简体   繁体   中英

On changing layout Orientation application crashes?

When i Change the layout Orientation application crashes in the simulator??

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_gravity="center_vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"><View android:layout_width="fill_parent" android:layout_height="10dp"></View><TableLayout android:layout_width="fill_parent"
    android:layout_height="150dp" android:background="@drawable/table_one">
    <TableRow android:layout_height="20dp" android:layout_width="fill_parent">
        <View android:layout_height="20dp" android:layout_width="fill_parent"></View></TableRow>
    <TableRow android:layout_width="fill_parent"
        android:layout_height="40dp"><TextView android:gravity="center|left"android:layout_width="70dp" android:layout_height="40dp"
            android:textColor="#000000" android:text="Name"
            android:layout_marginLeft="4dp" android:layout_weight="20" />
        <Spinner android:id="@+id/Spinner01" android:gravity="center"
            android:layout_width="250dp" android:layout_height="40dp"
            android:layout_marginRight="5dp" android:layout_weight="80"></Spinner>
    </TableRow>
    <TableRow android:layout_width="fill_parent"
        android:layout_height="40dp">

        <TextView android:gravity="center|left" android:textColor="#000000"
            android:layout_alignParentLeft="true" android:layout_width="70dp"
            android:layout_height="40dp" android:layout_weight="30"
            android:text="Status :" android:layout_marginLeft="4dp" />

        <TextView android:id="@+id/Spinner01" android:layout_width="250dp"
            android:layout_height="40dp" android:layout_weight="70"
            android:layout_marginRight="5dp"></TextView>
    </TableRow>
    <TableRow android:layout_width="fill_parent"
        android:layout_height="40dp">
        <TextView android:gravity="center|left" android:textColor="#000000"
            android:layout_width="70dp" android:layout_height="40dp"
            android:layout_weight="30" android:text="Type :"
            android:layout_marginLeft="4dp" />
        <TextView android:textColor="#250517"
            android:layout_gravity="center" android:id="@+id/Spinner01"
            android:layout_width="250dp" android:layout_height="40dp"
            android:layout_weight="70" android:layout_marginRight="5dp"></TextView>
    </TableRow>
</TableLayout>
<View android:layout_width="fill_parent" android:layout_height="10dp"></View>
<TableLayout android:layout_width="fill_parent"
    android:background="@drawable/table_one" android:layout_height="90dp">
    <TableRow android:layout_height="20dp">
        <View android:layout_height="20dp"></View>
    </TableRow>
    <TableRow android:layout_width="fill_parent"
        android:layout_height="40dp">
        <TextView android:gravity="center|left" android:textColor="#000000"
            android:layout_height="40dp" android:layout_weight="20"
            android:text="Document" android:layout_marginLeft="4dp"
            android:layout_width="70dp" />

        <EditText android:id="@+id/btn_browse" android:singleLine="true" android:layout_width="100dp"
            android:layout_height="40dp" android:layout_weight="80"
            android:layout_marginRight="5dp"></EditText>
    </TableRow>
</TableLayout>
<View android:layout_width="fill_parent" android:layout_height="10dp"></View>
<TableLayout android:orientation="horizontal"
    android:background="@drawable/my_bsckround" android:layout_width="fill_parent"
    android:gravity="center_vertical" android:layout_height="160dp">
    <TableRow android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <Button android:text="Print" android:id="@+id/btn_print"
            android:layout_width="106dp" android:layout_height="wrap_content"></Button>
        <Button android:text="Settings" android:id="@+id/btn_setting"
            android:layout_width="106dp" android:layout_height="wrap_content"></Button>
        <Button android:text="Cancel" android:id="@+id/btn_cncl"
            android:layout_width="106dp" android:layout_height="wrap_content"></Button>
    </TableRow>
</TableLayout>
<View android:layout_width="fill_parent" android:layout_height="10dp"></View>

Please use

<activity android:name=".ShareTweet" android:label="@string/app_name"
            android:screenOrientation="portrait" />

to make perfect code.

i hope this will help you. Add this with activity class in manifest file

android:configChanges="orientation|keyboardHidden">

When you rotate the screen, the activity is created again. Look in your onCreate() method for the problem.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM