2013-02-25 33 views
-1

嗨,RelativeLayout定位不正常

我想設計一個不依賴於屏幕大小的佈局。其實我正在設計一個樣本佈局,其中有一個大尺寸添加在屏幕的中心。在上部剩餘區域和下部剩餘部分的中間有文字。 XML是:

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

    <ImageView 
     android:id="@+id/ads_layout_large" 
     android:layout_width="300dp" 
     android:layout_height="250dp" 
     android:layout_centerInParent="true" 
     android:background="@android:color/background_light" /> 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_above="@id/ads_layout_large" 
     android:background="#fff000" 
     android:gravity="center" 
     android:text="@string/exit_enjoyed_text" /> 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_below="@id/ads_layout_large" 
     android:background="#fff000" 
     android:gravity="center" 
     android:text="@string/exit_enjoyed_text" /> 
</RelativeLayout> 

的問題是,它正在上部,文字恰恰是在其餘區域的中心,但較低的TextView已覆蓋一半的屏幕,可以請你幫我找出錯誤?或者其他方式來設計相同的?

回答

1

我覺得這裏是你的問題:

android:layout_height="fill_parent" 

設置你的TextView高度FILL_PARENT導致你的TextView延伸到達它的父的大小,使用WRAP_CONTENT或像「30DP」靜態值,而不是

+0

我需要保持在剩餘部分的中心。 同樣的事情在上面工作,但不在下面。 – Neo 2013-02-25 09:08:02

+0

用於在textview中對齊文本使用android:gravity =「center | center_vertical」,如果你希望textview得到居中使用它的父級使用layout_gravity =「center | center_vertical」.hope這個幫助 – 2013-02-25 09:14:14

+0

其實我想把屏幕分成三部分: 1>中間部分300dp x 250dp 2>餘下部分。 3>剩餘部分較少。 而我認爲它在android中簡單退出,但主要問題如何。 – Neo 2013-02-25 09:26:07