我的仪表板应用程序在不同的屏幕尺寸上迷路

时间:2015-05-23 07:26:52

标签: android android-layout screen-size

我是一位正在崭露头角的Android开发者,我正在创建一个包含仪表板的Android应用程序。我根据我的NEXUS 7平板电脑设计了仪表板。现在,当我在一个5英寸安卓手机中运行相同的应用程序时,所有的路线都迷失方向。有什么解决方案吗?所以在所有屏幕尺寸中它看起来都是一样的。 以下是我的代码

<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"
tools:context=".MainActivity"
android:background="#ffffffff">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="2"
    android:layout_marginTop="20dp"
    android:layout_marginRight="20dp"
    android:layout_marginLeft="20dp"
    android:layout_marginBottom="20dp"
    android:orientation="vertical"
    >
   <RelativeLayout
       android:layout_width="match_parent"
       android:layout_height="0.0dp"
       android:layout_weight="1">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="SpO2"
        android:textSize="100dp"
        android:layout_centerHorizontal="true"
        android:id="@+id/four_five"
        android:layout_marginTop="20dp"

        android:textColor="#ff7a0000" />
       <TextView
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="45% "
           android:textSize="100dp"
           android:layout_alignParentRight="true"
           android:layout_below="@+id/four_five"
           android:textColor="#ffef00b9" />

    <ImageButton
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="10dp"
        android:background="@drawable/spo2"/>
   </RelativeLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0.0dp"
        android:layout_weight="1"
        android:weightSum="3"
        android:layout_marginTop="10dp"
        >
        <RelativeLayout
            android:layout_width="0.0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:layout_marginRight="5dp">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="70dp"
                android:text="STEPS"
                android:layout_centerHorizontal="true"
                android:textSize="50dp"
                android:id="@+id/text_view3"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/text_view3"
                android:id="@+id/text_view4"
                android:layout_alignParentRight="true"
                android:text="1258"
                android:layout_marginRight="10dp"
                android:textSize="40dp"/>
        <ImageButton
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/steps"/>
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="0.0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            >
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/text_view5"
                android:text="bpm"
                android:textSize="50dp"
                android:layout_centerInParent="true"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/text_view6"
                android:layout_below="@+id/text_view5"
                android:text="5000"
                android:textSize="60dp"
                android:layout_centerHorizontal="true"/>
        <ImageButton
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/bpm"
            />
        </RelativeLayout>
        <RelativeLayout
            android:layout_width="0.0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:layout_marginLeft="5dp">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="KCal"
                android:id="@+id/text_view7"
                android:textSize="50dp"
                android:layout_marginTop="70dp"
                android:layout_centerHorizontal="true"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/text_view8"
                android:text="9876"
                android:layout_marginRight="10dp"
                android:layout_below="@+id/text_view7"
                android:textSize="40dp"
                android:layout_alignParentLeft="true"/>
        <ImageButton
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/kcal"/>
        </RelativeLayout>

        </LinearLayout>

    </LinearLayout>

<ImageView
    android:layout_width="250dp"
    android:layout_height="250dp"
    android:layout_centerInParent="true"
    android:id="@+id/image_view"
    android:background="@drawable/centre_button"/>

<ImageButton
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:layout_centerInParent="true"
    android:background="@drawable/main_centre_button"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:text="99°C"

    android:textSize="50dp"
    android:id="@+id/text_view9"/>

1 个答案:

答案 0 :(得分:0)

欢迎:) 让我们从20 dp开始作为例子。 无论屏幕是平板电脑,手机还是巨型电视屏幕,20 dp都是20 dp。 因此,整体问题是您使用固定测量来测量可变屏幕尺寸。解决方案是为不同的设备创建不同的布局,例如

纵向模式下的普通手机=布局 - 肖像

横向模式下的常规手机= layout-land

纵向平板电脑=布局 - 大画像

平板电脑风景=布局大片土地

您可以找到有关如何支持以下不同屏幕尺寸的更多信息,并且不会感觉太糟糕。一年或两年前,我也不是新手。

http://developer.android.com/training/multiscreen/screensizes.htmll

http://developer.android.com/training/basics/supporting-devices/screens.html