[英]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.