适用于所有屏幕尺寸的Android xml布局

时间:2014-01-15 05:16:58

标签: android xml android-layout

我想为所有布局创建一个xml文件,在设备中保持相同的比例和位置。

这是我想要创建的布局设计:

wanted layout

这是我的布局xml文件: 当我使用这个xml时,在某些屏幕中,圆形按钮与我的上图不同,而“图像”视图和“圆形按钮”中间的文本视图(0.0km)不在中间位置:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<RelativeLayout
    android:id="@+id/relativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginTop="50dp"
        android:layout_alignParentTop="true"

        android:src="@drawable/firstscreenimage" />

</RelativeLayout>

<TextView
    android:id="@+id/textView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/button1"
    android:layout_alignParentLeft="true"
    android:layout_marginBottom="92dp"
    android:gravity="right"
    android:text="0.0km"
    android:textSize="130dp" />

<Button
    android:id="@+id/button1"
    android:layout_width="400dp"
    android:layout_height="400dp"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="150dp"
    android:background="@drawable/animation0" />


 <TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/button1"
    android:textSize="35dp"
    android:layout_alignBottom="@+id/button1"
    android:layout_centerHorizontal="true"
    android:text="Start" />

 <EditText
     android:id="@+id/campa"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:layout_alignParentBottom="true"
     android:layout_centerHorizontal="true"
     android:layout_marginBottom="23dp"
     android:ems="10" >

     <requestFocus />
 </EditText>

</RelativeLayout>

这是错误的布局: wrong layout

请帮帮我,抱歉我的英语不好。谢谢....

2 个答案:

答案 0 :(得分:0)

试试这个

    <?xml version="1.0" encoding="utf-8"?>
        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <RelativeLayout
            android:id="@+id/relativeLayout1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_marginTop="50dp"
                android:layout_alignParentTop="true"

                android:src="@drawable/firstscreenimage" />

        </RelativeLayout>

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/button1"
            android:layout_alignParentRight="true"
            android:layout_marginRight="10dp"
            android:gravity="right"
            android:text="0.0km"
            android:textSize="130dp" />

        <Button
            android:id="@+id/button1"
            android:layout_width="400dp"
            android:layout_height="400dp"
            android:layout_centerInParent="true"
            android:background="@drawable/animation0" />




<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button1"
android:textSize="35dp"
android:layout_alignBottom="@+id/button1"
android:layout_centerHorizontal="true"
android:text="Start" />

 <EditText
     android:id="@+id/campa"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:layout_alignParentBottom="true"
     android:layout_centerHorizontal="true"
     android:layout_marginBottom="23dp"
     android:ems="10" >

     <requestFocus />
 </EditText>

</RelativeLayout>

答案 1 :(得分:0)

相关问题