[英]Android widget Relative Layout
I spent the last couple of days trying to make a layout. 我花了最后几天尝试进行布局。
They layout looks great on my phone with 480x800 screen, but is messed up on my phone with 540x960 screen. 在我的480x800屏幕的手机上,它们的布局看起来不错,但是在540x960屏幕的手机上却弄乱了。
I used dp expecting it would scale by density. 我使用dp期望它将按密度缩放。
What is going wrong? 怎么了?
Here is my code for the layout xml. 这是我的布局xml代码。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="15dip"
android:background="@drawable/gshock5">
<TextView
android:id="@+id/widgetday"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="50dip"
android:layout_marginTop="95sp"
android:layout_centerInParent="true"
android:text="DAY"
android:textColor="#003300"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textStyle="bold"/>
<TextView
android:id="@+id/widget1label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/widgetday"
android:layout_centerHorizontal="true"
android:clickable="true"
android:textColor="#003300"
android:text="Error"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold"/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="210dip">
<Button android:text="Click Me!"
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</RelativeLayout>
</RelativeLayout>
Try using a linear layout. 尝试使用线性布局。 Cause when the device is changed, sure it is scaled.
更换设备时的原因,请确保已缩放。 But, when using a relative layout, they are arranged relatively, and then scaled, which probably messed things up.
但是,当使用相对布局时,它们会相对布置,然后缩放,这可能会使事情搞砸。
<?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:layout_margin="15dip"
android:background="@drawable/gshock5"
android:orientation="vertical" >
<TextView
android:id="@+id/widgetday"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginRight="50dip"
android:layout_marginTop="95dip"
android:text="DAY"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#003300"
android:textStyle="bold" />
<TextView
android:id="@+id/widget1label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/widgetday"
android:layout_centerHorizontal="true"
android:clickable="true"
android:text="Error"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#003300"
android:textStyle="bold" />
<Button
android:id="@+id/button"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/widget1label"
android:text="Click Me!" />
</RelativeLayout>
This may solve your problem. 这样可以解决您的问题。 Try to use minimal layout for the UI.
尝试对UI使用最小的布局。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.