我是一个初露头角的android开发者,我正在创建一个包含仪表板的android应用程序。我根据我的NEXUS 7平板电脑设计了仪表盘。现在,当我在一部5英寸的android手机上运行同样的应用程序时,所有的对齐都是迷失方向的。有什么解决方案吗?所以它在所有屏幕尺寸下看起来都是一样的。下面是我的代码
<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"/>
发布于 2015-05-23 17:20:20
欢迎:)让我们以20 dp为例开始。无论屏幕是平板电脑、手机还是电视巨幕,20dp都是20dp。所以总的问题是你对不同的屏幕尺寸使用固定的测量。解决方案是为不同的设备创建不同的布局,例如
画像模式下的普通手机=布局-画像
横向模式下的普通电话=布局-土地
纵向中的写字板=布局-大-纵向
景观中的写字板=布局-大片土地
你可以在下面找到更多关于如何支持不同屏幕尺寸的信息,不要觉得太糟糕了。就在一两年前,我还是个新手。
http://developer.android.com/training/multiscreen/screensizes.htmll
和
http://developer.android.com/training/basics/supporting-devices/screens.html
https://stackoverflow.com/questions/30410126
复制相似问题