簡體   English   中英

如何使用Android的不同顯示尺寸創建布局

[英]How to create layout with android's different display size

我從圖形工具在xml文件中創建布局時遇到的我的問題。 RelativeLayout太糟糕了! 我不知道要使用哪種布局。當我放置一個imageview和一個imagebutton時,在模擬器中會以一種不好的方式顯示,一個又一個。 我能做什么? 有沒有很好的教程,我可以在其中學習如何按不同顯示器尺寸的百分比來調整圖像和布局的大小? 我嘗試這個:

 <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>

但是當我展示它不是很好

關於多屏支持,請看這里
您需要為小,中,大屏幕尺寸添加不同的布局。

因為您正在使用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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM