2011-05-20 57 views
-1

我有以下布局Realtive布局与绝对布局

<?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?

+1

你能定义什么日e“正确的位置”是? – jkhouw1 2011-05-20 09:52:07

+0

这就是问题所在。我有一个适合文本的背景。该图像有一个额外的小窗口,在那里显示文本视图。它的nessesry定义绝对的方式,在每个屏幕尺寸的文本和backgorund是在正确positin。 – user758610 2011-05-20 11:52:44

回答

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到屏幕的右侧。如果你想要把保证金从屏幕的右侧,你也可以在你的TextView使用下面的代码:

android:layout_marginRight="10dip" 
+0

对不起这个工作 - 即使保证金正确。文字从不显示在右侧 - 它粘在左上角。我不知道这是。 – user758610 2011-05-20 11:49:31

+0

喔..以下为你的TextView标签代码右侧添加文字:安卓重力=“右” – mudit 2011-05-20 11:59:05

+0

好吧我的错SRY。有效。现在是dip值的一个相对值吗?因为如果不是,那么如果屏幕较小,文本视图将在右侧播放得太多。或者这是由相对布局intself处理的。谢谢你的回答! – user758610 2011-05-20 12:37:17

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