Cruces
Cruces

Reputation: 3129

How can I change a chain's height in android's constraint layout

I'm creating a login form which contains two layouts within a constraint layout

The code is this:

<?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"
    android:background="#424242"
    android:orientation="vertical">
    <android.support.constraint.Guideline
        android:id="@+id/login_guideline_start"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="@dimen/guideline_perc_start" />
    <android.support.constraint.Guideline
        android:id="@+id/login_guideline_end"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="@dimen/guideline_perc_end" />
    <android.support.v7.widget.AppCompatImageView
        android:id="@+id/login_logo"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:scaleType="center"
        app:layout_constraintBottom_toTopOf="@+id/login_form"
        app:layout_constraintLeft_toLeftOf="@id/login_guideline_start"
        app:layout_constraintRight_toLeftOf="@id/login_guideline_end"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/rooll" />

    <android.support.constraint.ConstraintLayout
        android:id="@+id/login_form"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="@id/login_guideline_start"
        app:layout_constraintRight_toLeftOf="@id/login_guideline_end"
        app:layout_constraintTop_toBottomOf="@id/login_logo">

        --the controls for the login form go here--

    </android.support.constraint.ConstraintLayout>

</android.support.constraint.ConstraintLayout>

the guidelines are used to make the form show in the middle on tablets with landscape view, and fill the screen on phones in portrait view

My problem is that because I created a chain between the logo and the form, the height of the chain between parent logo and form is always the same.

Is there a way to alter the chain's height? for example can I make the height of the constraint between parent and logo be 0dp and the height of the chain between logo and form be half of that as the one between form and parent?

Thanks in advance for any help you can provide

Upvotes: 0

Views: 985

Answers (1)

Cheticamp
Cheticamp

Reputation: 62841

Take a look at this tutorial. You may want to focus on this part dealing with weights in chains.

Weighted: When the chain is set to either spread or spread inside, you can fill the remaining space by setting one or more views to “match constraints” (0dp). By default, the space is evenly distributed between each view that's set to "match constraints," but you can assign a weight of importance to each view using thelayout_constraintHorizontal_weight and layout_constraintVertical_weight attributes. If you're familiar with layout_weight in a linear layout, this works the same way. So the view with the highest weight value gets the most amount of space; views that have the same weight get the same amount of space.

Upvotes: 0

Related Questions