我有以下布局
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/flowerpower">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_y="200dip"
android:textColor="#000000"
android:text="Test"/>
</AbsoluteLayout>
现在我遇到的问题是,在不同屏幕尺寸的显示器上,TextView不是正确的位置,因为它是绝对布局。如何使用RelativeLayout使这个工作?我建议这是正确的解决方案吗? RealtiveLayout?
答案 0 :(得分:1)
首先,尽量不要使用Absolute Layout
因为它在Android SDK中已弃用。
第二个代码,试试这个:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/flowerpower">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textColor="#000000"
android:text="Test"/>
</RelativeLayout>
这会将您的textview对齐到屏幕右侧。如果您想从屏幕右侧放置边距,您还可以在文本视图中使用以下代码:
android:layout_marginRight="10dip"
答案 1 :(得分:0)
对于这样一个简单的布局,您可以使用LinearLayout。但是你应该查看Android Layout Documentation。
答案 2 :(得分:0)
http://developer.android.com/reference/android/widget/AbsoluteLayout.html
http://developer.android.com/reference/android/widget/LinearLayout.html
答案 3 :(得分:0)
试试这个:
<RelativeLayout android:id="@+id/Layout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/flowerpower">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textColor="#000000"
android:text="Hello world !!"/>
</RelativeLayout>
注意:请遵循此link