簡體   English   中英

如何在不使用絕對布局的情況下正確定位android布局?

[英]How to correctly position android layout without using Absolute Layout?

對不起,這是一個菜鳥問題,但我很討厭布局。 我將如何制作一個放置flashlight_button的布局,以便保留頂部和底部的圖像視圖之間的比例。

在nexus s(800x480)上看起來還可以,這就是我想要的

...圖片 ...

但是很明顯,當我切換到銀河系聯系(1280 x 720)時,它將中間按鈕稍微移到頂部,就像這樣(因此,它不會像在Nexus上那樣保留頂部和底部邊距之間的比率)

...圖片...

布局在這里:

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

因此它只是將頂部和底部的圖像視圖錨定到父邊緣,並且使用layout_maginBottom向下按下中間按鈕。 我正在為不同的密度提供明顯的縮放圖像,並提供明顯的密度像素來表示尺寸,因此在更大的屏幕上看起來還不夠。

什么是正確的方法? 不同的.xml文件或..?

//抱歉,我仍然無法發布圖片,希望您能想象得到。

您是否考慮過根據父母的中心放置手電筒圖像? 因此,現在您要向下推手電筒圖像(根據頂部圖像位置)。 使手電筒圖像居中對齊並為其提供一定的底邊距(根據您的設計將其推高一點)會更准確嗎?

暫無
暫無

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

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