今天我發生了一件奇怪的事情,並引發了數小時的挫折感和憤怒管理問題。將按鈕從相對佈局改爲線性佈局奇怪的副作用
我有一個可用的Android幻燈片應用程序。但是,我對這些按鈕(它們處於相對佈局)感到不滿,並將它們移動到線性佈局。但是,在運行我的應用程序時,按鈕的行爲會被交換(即Button 1執行Button 2的工作,反之亦然)。我可以通過更改其中一個按鈕的ID來解決這個問題,而不是所有的(不起作用)。與此相關的是,當我切換方向時,我的應用程序開始崩潰。之前我有過相對佈局時它曾經工作過。 (我正在使用處理程序更改幻燈片的用戶界面)
我無法解決此問題,因此我恢復爲相對佈局,但我想知道這可能是如何發生的。導致問題
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:contentDescription="@string/imageView"
android:scaleType="centerInside"
android:src="@drawable/image1" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageButton
android:id="@+id/startStop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:contentDescription="@string/startStop"
android:src="@drawable/ic_menu_slideshow" />
<ImageButton
android:id="@+id/next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="false"
android:layout_toRightOf="@+id/startStop"
android:contentDescription="@string/next"
android:src="@drawable/ic_media_next" />
<ImageButton
android:id="@+id/previous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="false"
android:layout_toLeftOf="@+id/startStop"
android:contentDescription="@string/previous"
android:src="@drawable/ic_media_previous" />
</RelativeLayout>
代碼:
,工程佈局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:contentDescription="@string/imageView"
android:scaleType="centerInside"
android:src="@drawable/image1" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#30eee9e9" >
<ImageButton
android:id="@+id/previous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/previous"
android:src="@drawable/ic_media_previous" />
<ImageButton
android:id="@+id/bla"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/startStop"
android:src="@drawable/ic_menu_slideshow" />
<ImageButton
android:id="@+id/next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/next"
android:src="@drawable/ic_media_next" />
你可以發佈你的佈局xml和代碼,你處理按鈕點擊? – vipsy 2012-08-06 16:27:32
您必須使用相對佈局的LeftOff或RightOff功能(作爲父母),是這樣嗎? – 2012-08-06 16:41:26
我猜你應用程序崩潰後,由於ClassCast或NullPointer異常的方向更改。你有不同的肖像和風景佈局嗎?如果是這樣,你需要更新兩個佈局。但沒有相關的**代碼**和** logcat **錯誤,我們只能猜測。 – Sam 2012-08-06 17:03:09