1
我一直在開發一個應用程序在Android上開始。我所遇到的問題,我的佈局將無法正常顯示,當它轉到其他像這樣的不同方向:佈局不能正確地重新調整方向更改
這裏是我的垂直佈局代碼:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="3dip" >
<EditText
android:id="@+id/passText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="5"
android:hint="Passcode"
android:inputType="textPassword" />
<EditText
android:id="@+id/messageText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="top|left"
android:hint="Message" >
<requestFocus />
</EditText>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="5"
android:orientation="horizontal"
android:weightSum="100" >
<Button
android:id="@+id/encodeButton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="50"
android:text="Encode" />
<Button
android:id="@+id/decodeButton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="50"
android:text="Decode" />
</LinearLayout>
</LinearLayout>
這裏是我的景觀佈局代碼:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="8dip" >
<EditText
android:id="@+id/passText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:hint="Passcode"
android:inputType="textPassword" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/messageText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:gravity="top|left"
android:hint="Message" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="horizontal"
android:weightSum="100" >
<Button
android:id="@+id/encodeButton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="50"
android:text="Encode" />
<Button
android:id="@+id/decodeButton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="50"
android:text="Decode" />
</LinearLayout>
</LinearLayout>
我寧願建議你使用'RelativeLayout'實現這個 – waqaslam 2012-02-29 21:46:08
能否請您顯示出與使用該佈局的活動清單片段? – muffinmad 2012-02-29 22:54:36
我通過使用相對佈局得到了這個。謝謝 – globalninja 2012-02-29 23:37:48