Перевести LinearLayout в ConstraintLayout - PullRequest
0 голосов
/ 29 мая 2018

Я учусь с помощью ConstraintLayout, но до сих пор не могу привыкнуть к нему.Не могли бы вы помочь мне с «переводом» этого макета, созданного с помощью LinearLayout, в ConstraintLayout, чтобы помочь мне понять, как с помощью этого можно построить «немного» более сложные макеты?С LinearLayout это просто, но создание такого типа макета с использованием ограничений кажется проблематичным.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.xxx.MainActivity">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_marginTop="8dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="1"
        android:orientation="vertical">

        <EditText
            android:id="@+id/editText_main_overallTime"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:inputType="time" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="1"
        android:orientation="vertical">

        <TextView
            android:id="@+id/tv1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Exercised done"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/textView_main_exercisesDone"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:textSize="18sp"
            tools:text="3/15" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="1"
        android:orientation="vertical">

        <TextView
            android:id="@+id/tv2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:gravity="center"
            android:text="Next exercise"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/textView_main_nextExerciseName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:gravity="center"
            android:textSize="18sp"
            tools:text="Paradiddle" />
    </LinearLayout>

</LinearLayout>

<View
    android:id="@+id/view"
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="@color/colorPrimaryDark"
    android:layout_marginTop="8dp"
    android:layout_marginBottom="8dp"/>

<TextView
    android:id="@+id/textView_main_currentExerciseName"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:textSize="24sp"
    tools:text="Name of the excercise" />

<EditText
    android:id="@+id/editText_main_timeLeft"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="time" />

<ImageView
    android:id="@+id/imageView_main_exercise"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_weight="1"
    app:srcCompat="@mipmap/ic_launcher" />

<ImageButton
    android:id="@+id/imageButton_main_power"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    app:srcCompat="@android:drawable/ic_media_play" />

</LinearLayout>

1 Ответ

0 голосов
/ 29 мая 2018

Вы можете достичь желаемого результата, используя Android Studio, выполнив следующие действия:

  1. Откройте вкладку «Дизайн» -> Дерево компонентов -> Щелкните правой кнопкой мыши -> Преобразовать линейный макет в макет ограничения

convert layout

Выберите соответствующую опцию и нажмите OK options

Проверьте вкладку «Текст», ваш макет теперь будет переведен в ConstraintLayout.

...