如何在另一个内部拉伸一个RelativeLayout?

时间:2014-06-01 23:21:09

标签: android android-layout

我在另一个内部有一个RelativeLayout,我希望内部布局的宽度与外部相同。

我有什么:

one

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:visibility="visible"
    tools:context=".MainActivity" >    

    <RelativeLayout
        android:id="@+id/fragment_container"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/lady"
        android:visibility="visible" >
    </RelativeLayout>
</RelativeLayout>

我需要什么:

two

3 个答案:

答案 0 :(得分:1)

使内部RelativeLayout宽度match_parent代替wrap_content

答案 1 :(得分:0)

您需要使用边距

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:visibility="visible"
    tools:context=".MainActivity" >    

    <RelativeLayout
        android:id="@+id/fragment_container"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"

        android:layout_marginLeft="@dimen/activity_horizontal_margin"
        android:layout_marginRight="@dimen/activity_horizontal_margin"
        android:layout_marginBottom="@dimen/activity_vertical_margin"

        android:layout_below="@+id/lady"
        android:visibility="visible" >
    </RelativeLayout>
</RelativeLayout>

答案 2 :(得分:0)

您需要做的是删除外部相对布局的android:paddingLeftandroid:paddingRight填充是与第一张图片的差距)并使您的内在亲戚布局的宽度为match_parent

示例:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingTop="@dimen/activity_vertical_margin" 
android:visibility="visible"
tools:context=".MainActivity" >    

<RelativeLayout
    android:id="@+id/fragment_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"

    android:layout_marginLeft="@dimen/activity_horizontal_margin"
    android:layout_marginRight="@dimen/activity_horizontal_margin"
    android:layout_marginBottom="@dimen/activity_vertical_margin"

    android:layout_below="@+id/lady"
    android:visibility="visible" >
</RelativeLayout>