如何将约束布局转换为相对布局?

时间:2018-01-04 18:59:46

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

我目前正在尝试将我的约束布局转换为相对布局,但不确定如何处理“app:”参数,这些参数引用约束顶部,底部等。这是我的代码澄清:

<?xml version="1.0" encoding="utf-8"?>
<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/myFragmentConstaintLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/gray"
    android:orientation="vertical">

    <RelativeLayout
        android:id="@+id/activeSpeakerContainer"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toTopOf="@+id/groupList"
        app:layout_constraintDimensionRatio="1:1"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/myStatusContainer">

        <FrameLayout
            android:id="@+id/activeSpeakerVideo"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/black" />

        <ImageView
            android:id="@+id/activeSpeakerImage"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:padding="48dp"
            android:background="@color/black"
            android:src="@drawable/my_default_profile" />

        <TextView
            android:id="@+id/myParticipantCountText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:ellipsize="end"
            android:lines="1"
            android:background="@drawable/rounded_rect"
            android:layout_marginStart="18dp"
            android:layout_marginTop="18dp"
            android:drawablePadding="2dip"
            android:paddingLeft="10dip"
            android:textColor="@color/gray6"
            android:textSize="16sp"
            android:textStyle="bold"
            android:drawableLeft="@drawable/drawable_user_count_icon"
            android:drawableStart="@drawable/drawable_user_count_icon"/>

        <ImageView
            android:id="@+id/image_mark"
            android:layout_width="130dp"
            android:layout_height="28dp"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:layout_marginBottom="36dp"
            android:layout_marginRight="16dp"
            android:layout_marginEnd="16dp"
            android:src="@drawable/image_mark_blue" />

        <TextView
            android:id="@+id/activeSpeakerName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:background="#AA555555"
            android:ellipsize="end"
            android:gravity="center_horizontal|bottom"
            android:lines="1"
            android:textColor="@color/gray6"
            android:textSize="16sp"
            tools:text="user@gmail.com" />

        <TextView
            android:id="@+id/DurationText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="8dp"
            android:layout_marginStart="8dp"
            android:layout_alignParentStart="true"
            android:layout_alignParentBottom="true"
            android:gravity="start|bottom"
            android:lines="1"
            android:textColor="@color/gray6"
            android:textSize="14sp"
            tools:text="03:16" />

    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/screenShareContainer"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginTop="0dp"
        android:layout_marginStart="0dp"
        android:layout_marginBottom="0dp"
        android:layout_marginLeft="0dp"
        android:layout_marginRight="0dp"
        app:layout_constraintDimensionRatio="16:9"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/myStatusContainer"
        app:layout_constraintBottom_toTopOf="@+id/myButtonContainer">

        <PinchandZoomLayout
            android:id="@+id/screenShareVideo"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/black"/>

        <ImageButton
            android:id="@+id/screenShareToggle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:layout_marginBottom="36dp"
            android:layout_marginLeft="16dp"
            android:layout_marginStart="16dp"
            android:background="@android:color/transparent"
            android:src="@drawable/ic_video_cam_switch" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/myStatusContainer"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="#AA555555"
        android:padding="8dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <TextView
            android:id="@+id/myNameText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:ellipsize="end"
            android:lines="1"
            android:textColor="@color/gray6"
            android:textSize="14sp"
            tools:text="user2@gmail.com" />

        <ImageButton
            android:id="@+id/myButtonVideoRotate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:background="@android:color/transparent"
            android:src="@drawable/ic_video_cam_switch" />

    </RelativeLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/groupList"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:visibility="invisible"
        app:layout_constraintBottom_toTopOf="@+id/myButtonContainer"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/activeSpeakerContainer">

    </android.support.v7.widget.RecyclerView>

    <RelativeLayout
        android:id="@+id/myProgressContainer"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="@+id/groupList"
        app:layout_constraintLeft_toLeftOf="@+id/groupList"
        app:layout_constraintRight_toRightOf="@+id/groupList"
        app:layout_constraintTop_toTopOf="@+id/groupList">

        <TextView
            android:id="@+id/myProgressName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="8dp"
            android:gravity="center_horizontal"
            android:textColor="@color/gray6"
            android:textSize="20sp"
            tools:text="My Name" />

        <TextView
            android:id="@+id/myProgressText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/myProgressName"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="8dp"
            android:gravity="center_horizontal"
            android:text="@string/my_status_connecting"
            android:textColor="@color/gray6"
            android:textSize="16sp" />

    </RelativeLayout>

    <include
        android:id="@+id/myButtonContainer"
        layout="@layout/layout_my_button_bar_1_row"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent" />


    <android.support.constraint.ConstraintLayout
        android:id="@+id/myButtonContainerUnavailable"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:visibility="gone"
        app:layout_constraintBottom_toBottomOf="@+id/myButtonContainer"
        app:layout_constraintLeft_toLeftOf="@+id/myButtonContainer"
        app:layout_constraintRight_toRightOf="@+id/myButtonContainer"
        app:layout_constraintTop_toTopOf="@+id/myButtonContainer"
        tools:visibility="visible">

        <Button
            android:id="@+id/myButtonCancel"
            style="@style/myButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawableTop="@drawable/btn_my_end"
            android:text="@string/dialog_button_cancel"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toLeftOf="@+id/myButtonRetry"
            app:layout_constraintTop_toTopOf="parent" />

        <Button
            android:id="@+id/myButtonRetry"
            style="@style/myButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawableTop="@drawable/btn_my_retry"
            android:text="@string/button_try_again"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toRightOf="@+id/myButtonCancel"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

    </android.support.constraint.ConstraintLayout>

</android.support.constraint.ConstraintLayout>

我刚尝试用相对布局替换“android.support.constraint.ConstraintLayout”,但是这些参数“app:layout_constraint ...”更难处理。有什么更简单的方法可以解决这个问题吗?

提前致谢。

1 个答案:

答案 0 :(得分:1)

我正在使用Android Studio版本3.1.2

无需做那么多复杂的事情。只需右键单击 如图所示,在组件树中选择布局名称,然后选择选项convert view,然后选择要使用的布局。

enter image description here