2011-05-20 59 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