layout_constraintGuide_percent не работает - Android - PullRequest
0 голосов
/ 31 января 2019

Я использую ConstraintLayout.Я хочу разделить страницу на два цвета, и я хочу иметь макет на весь экран с 70% высоты.

это мой код:

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent">




    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:weightSum="2"
        android:orientation="vertical" >

        <android.support.v7.widget.CardView android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            app:cardBackgroundColor="@color/wikitude_primary">

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

        <LinearLayout android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="#fff"></LinearLayout>


    </LinearLayout>

    <android.support.constraint.Guideline
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:id="@+id/guideline"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.8"/>


</android.support.constraint.ConstraintLayout>

, но app:layout_constraintGuide_percentне работает.

Я хочу сделать вид, подобный этому:

https://www.pinterest.com/pin/189995678015932713/

1 Ответ

0 голосов
/ 01 февраля 2019

Есть несколько вещей, которые не так в вашем макете.В частности, вы не устанавливаете ограничения для руководства.Попробуйте следующий макет, который создает это изображение в конструкторе Android Studio.Я добавил текстовое представление для идентификации разделов, но в противном случае они не нужны.

enter image description here

activity_main.xml

<android.support.constraint.ConstraintLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:orientation="vertical"
        android:weightSum="2"
        app:layout_constraintBottom_toTopOf="@id/guideline"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            app:cardBackgroundColor="@color/wikitude_primary">

            <TextView
                android:id="@+id/textView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="CardView"
                android:textSize="24sp"
                android:textStyle="bold" />
        </android.support.v7.widget.CardView>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="#fff"
            android:gravity="center"
            android:orientation="vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Bottom LinearLayout"
                android:textSize="24sp"
                android:textStyle="bold" />
        </LinearLayout>

    </LinearLayout>

    <android.support.constraint.Guideline
        android:id="@+id/guideline"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.7" />


</android.support.constraint.ConstraintLayout>
...