RelativeLayout定位无法正常工作

时间:2013-02-25 08:10:45

标签: android android-layout 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 个答案:

答案 0 :(得分:1)

我认为这是你的问题:

android:layout_height="fill_parent"

将TextView高度设置为fill_parent会导致textview扩展到达其父级大小,使用wrap_content或静态值,如“30dp”而不是