2011-10-04 210 views
0

我從圖形工具創建xml文件中的佈局時出現問題。 RelativeLayout是可怕的!我不知道要使用哪個佈局。當我放置一個imageview和一個imagebutton時,模擬器將以不好的方式顯示,其中一個會顯示。我能做什麼?有沒有一個很好的教程,我可以學習如何調整圖像和佈局的百分比不同的顯示大小? 我試試這個:如何使用android的不同顯示尺寸創建佈局

<RelativeLayout android:layout_width="match_parent" android:id="@+id/relativeLayout1" android:layout_height="match_parent"> 
    <LinearLayout android:layout_width="wrap_content" android:id="@+id/linearLayout1" android:orientation="vertical" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentLeft="true"> 
     <ImageView android:id="@+id/imageView1" android:src="@drawable/testotrova" android:layout_width="243dp" android:layout_height="48dp"></ImageView> 
    </LinearLayout> 
    <ImageButton android:layout_width="wrap_content" android:src="@drawable/info" android:layout_height="wrap_content" android:id="@+id/imageButton1" android:layout_alignParentTop="true" android:layout_alignParentRight="true"></ImageButton> 
</RelativeLayout> 

但是當我顯示這是不好的

+0

你可以在你想要達到的目標上添加一些圖片嗎? 嘗試刪除LinearLayout,因爲在這裏沒有必要。 – Maggie

回答

2

關於多屏幕的支持,看看here
您將需要添加不同的屏幕尺寸小,正常和大的佈局。

1

它們顯示在另一個上,因爲你正在使用RelativeLayour,他們是固定在上面兩者(圖片和文字)左:

android:layout_alignParentTop="true" android:layout_alignParentLeft="true" 

我強烈建議你使用LinearLayout,如果你只有幾個項目。 (http://www.learn-android.com/2010/01/05/android-layout-tutorial/4/)

爲您的圖片大小,如果你想有一個百分比,請使用:

android:layout_height="0dip" 
    android:layout_weight="1" 

http://developer.android.com/resources/articles/layout-tricks-efficiency.html

+0

實際上一個是alignParentRight,另一個是alignParentLeft,但我認爲Button會佔用很大的空間以適應ImageView所留下的空間,而ImageView是具有固定大小的唯一元素。 – banzai86

+0

後宮,你是完全正確的! –

相關問題