2012-07-26 23 views
2

即时对不起,这是一个noob问题,但我吮吸布局。我将如何制作一个布局来定位flashlight_button,以便保持顶部和底部的图像浏览比例。如何在不使用绝对布局的情况下正确定位android布局?

它看起来在Nexus S(800×480)好吧,我是这么希望

...图片...

但很明显,当我切换到的Galaxy Nexus(1280×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" /> 

所以它只是锚的顶部和底部imageviews到父边缘,并且中间的按钮只是压下使用layout_maginBottom。我提供了不同密度的缩放图像以及明显的密度像素来表示大小,因此在大屏幕上看起来不够。

什么是正确的方法来做到这一点?不同的.xml文件或..?

//对不起,我还是不能发布图片,希望你能想象得到。

+0

'layout_centerInParent'是你正在寻找的属性我相信。 – DeeV 2012-07-26 18:12:03

+0

可以发布实际图片而不是“...图片...”。目前还不清楚最终结果应该是什么 – 2012-07-26 18:13:22

+0

对不起,我是新来的,需要10张声望才能发布图片... @DeeV:我知道如何居中它,但我不想让图像居中,它的一个位偏移向上,它的一个设计我在Photoshop中和IM即时通讯试图实现这个 – urSus 2012-07-26 18:14:28

回答

1

您是否考虑根据父母的中心放置手电筒图像? 因此,现在您正在按下手电筒图像(根据顶部图像位置)。让手电筒图像居中对齐并给它一些底部边缘(根据您的设计将其推高一点)会更准确吗?

+0

感谢您的答案,但这不工作,它保持居中,即使底部边缘OD 200dp urSus 2012-07-27 00:35:07