gpt4 book ai didi

android - 如何在不使用绝对布局的情况下正确定位android布局?

转载 作者:行者123 更新时间:2023-11-29 02:02:47 25 4
gpt4 key购买 nike

对不起,这是一个菜鸟问题,但我很不擅长布局。我将如何制作定位 flashlight_button 的布局,以便保持顶部和底部 ImageView 之间的比例。

在 nexus s (800x480) 上看起来不错,这就是我想要的

...图片...

但很明显,当我切换到 galaxy nexus (1280 x 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" />

所以它只是将顶部和底部 ImageView 锚定到父边缘,而中间按钮只是使用 layout_maginBottom 按下。我为不同的密度和明显的密度像素提供缩放图像来表示尺寸,所以在更大的屏幕上似乎还不够。

正确的做法是什么?不同的 .xml 文件或 ..?

//抱歉我还是发不了图片,希望你能想象得到。

最佳答案

您是否考虑过根据 parent 的中心放置您的手电筒图像?所以现在你正在向下推手电筒图像(根据顶部图像位置)。使手电筒图像居中对齐并给它一些底边距(根据您的设计将其推高一点)会更准确吗?

关于android - 如何在不使用绝对布局的情况下正确定位android布局?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11675377/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com