如何为所有屏幕尺寸保持相同的布局(android)?

时间:2014-12-26 02:48:02

标签: android xml android-layout android-fragments

我在RelativeLayout中有一个片段。这个片段包含一个不同的imageView和trext。除了一件事,一切都很好。如果屏幕空间太大,就像我使用像Nexus 10或平板电脑这样的屏幕变得平坦,我的xml代码如下所示,我如何平衡所有屏幕尺寸的相同布局与xml文件中的更改..

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

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="@string/time"
        android:textColor="#ffffff"
        android:textSize="29sp" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/imageView1"
        android:contentDescription="@string/active"
        android:layout_marginRight="30dp"
        android:src="@drawable/active" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_alignBottom="@+id/textView1"
        android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@+id/imageView2"
        android:contentDescription="@string/wifi"
        android:src="@drawable/wifi" />

    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/imageView2"
        android:background="#ff0000"
        android:contentDescription="@string/search"
        android:src="@drawable/search" />

    <ImageView
        android:id="@+id/imageView4"
        android:layout_width="230dp"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignTop="@+id/imageView3"
        android:layout_toLeftOf="@+id/imageView3"
        android:layout_marginRight="10dp"
        android:background="#64b5f6"
        android:contentDescription="@string/weather"
        android:src="@drawable/weather" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/imageView4"
        android:layout_alignLeft="@+id/imageView4"
        android:layout_alignRight="@+id/imageView4"
        android:layout_alignTop="@+id/imageView4"
        android:text="@string/degree"
        android:textColor="#ffffff"
        android:textSize="30sp" />

    <ImageView
        android:id="@+id/imageView5"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/imageView4"
        android:layout_marginTop="10dp"
        android:background="#ff0000"
        android:contentDescription="@string/calender"
        android:src="@drawable/calend" />

    <ImageView
        android:id="@+id/imageView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/imageView5"
        android:layout_toRightOf="@+id/imageView5"
        android:background="#64b5f6"
        android:layout_marginLeft="10dp"
        android:contentDescription="@string/player"
        android:src="@drawable/wmp" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/imageView5"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="10dp"
        android:text="@string/agenda"
        android:textColor="#ffffff"
        android:textSize="30sp" />

    <ImageView
        android:id="@+id/imageView7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/imageView5"
        android:layout_alignLeft="@+id/imageView6"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/imageView6"
        android:layout_marginTop="10dp"
        android:background="#ffb74d"
        android:contentDescription="@string/gallary"
        android:src="@drawable/pictures" />

</RelativeLayout>

1 个答案:

答案 0 :(得分:0)