即時對不起,這是一個noob問題,但我吮吸佈局。我將如何製作一個佈局來定位flashlight_button,以便保持頂部和底部的圖像瀏覽比例。如何在不使用絕對佈局的情況下正確定位android佈局?
它看起來在Nexus S(800×480)好吧,我是這麼希望
...圖片...
但很明顯,當我切換到的Galaxy Nexus(1280×720),它的移動中間按鈕一個位到上方,這樣的(因此它不保留頂部和底部邊緣之間的比率作爲Nexus S的設計)
...圖像...
佈局是在這裏:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:padding="20dp" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="50dp"
android:contentDescription="@string/application_logo_description"
android:src="@drawable/mylight" />
<ImageButton
android:id="@+id/settings_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@null"
android:contentDescription="@string/settings_button_description"
android:src="@drawable/settings_button" />
<ImageButton
android:id="@+id/flashlight_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView1"
android:layout_centerHorizontal="true"
android:background="@null"
android:contentDescription="@string/flashlight_button_description"
android:src="@drawable/flashlight_button_selector" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/ad_button"
android:layout_centerHorizontal="true"
android:contentDescription="@string/powered_by_description"
android:src="@drawable/powered_by" />
<ImageButton
android:id="@+id/ad_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@null"
android:contentDescription="@string/ad_button_description"
android:src="@drawable/freeml" />
所以它只是錨的頂部和底部imageviews到父邊緣,並且中間的按鈕只是壓下使用layout_maginBottom。我提供了不同密度的縮放圖像以及明顯的密度像素來表示大小,因此在大屏幕上看起來不夠。
什麼是正確的方法來做到這一點?不同的.xml文件或..?
//對不起,我還是不能發佈圖片,希望你能想象得到。
'layout_centerInParent'是你正在尋找的屬性我相信。 – DeeV 2012-07-26 18:12:03
可以發佈實際圖片而不是「...圖片...」。目前還不清楚最終結果應該是什麼 – 2012-07-26 18:13:22
對不起,我是新來的,需要10張聲望才能發佈圖片... @DeeV:我知道如何居中它,但我不想讓圖像居中,它的一個位偏移向上,它的一個設計我在Photoshop中和IM即時通訊試圖實現這個 – urSus 2012-07-26 18:14:28