如何在xml的框架布局中嵌套约束布局?

时间:2018-05-23 12:58:21

标签: android android-layout android-fragments android-constraintlayout android-relativelayout

您好我是Android Studio的新手,目前在我的activity_main xml中,我有一些带有一些文本视图的约束布局。

<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/country_detail"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="edu.monash.fit2081.countryinfo.CountryDetails">

<TextView
    android:id="@+id/textView"
    android:layout_width="150dp"
    android:layout_height="25dp"
    //some code here

现在我想将它更改为片段并将该活动作为底部片段。我制作了这样的片段,但是如何将布局嵌套到我的帧布局中?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:id="@+id/content_main"
                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"
                tools:context="edu.monash.fit2081.database_4.MainActivity">

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
                 android:id="@+id/fragment_top"
                 android:layout_width="match_parent"
                 android:layout_height="match_parent"
                 android:background="@drawable/fragment_border"
        />

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
                 android:id="@+id/country_detail"
                 android:layout_width="match_parent"
                 android:layout_height="match_parent"
                 android:layout_below="@id/fragment_top"
                 android:background="@drawable/fragment_border"
        />

    </RelativeLayout>

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

FrameLayout是一个ViewGroup,就像RelativeLayout:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
                 android:id="@+id/country_detail"
                 android:layout_width="match_parent"
                 android:layout_height="match_parent"
                 android:layout_below="@id/fragment_top"
                 android:background="@drawable/fragment_border"
        >
    <android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/country_detail"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="edu.monash.fit2081.countryinfo.CountryDetails">

    <TextView
        android:id="@+id/textView"
        android:layout_width="150dp"
        android:layout_height="25dp"
        />

</FrameLayout>