Sunny
Sunny

Reputation: 7604

Android: ConstraintLayout - How to create a chain with equal weights

I have two views which have to be placed next to each other horizontally and they need to occupy 50% of the space. This can be done via guidelines easily.

But the issue is that each of the views has to be able to move to take the space of the other view in case the other view is gone. This is not possible via guidelines but possible when chains are used.

But the issue with the chain is that i am not able to make sure both (when both are visible) take up 50% of the total width horizontal areas assigned to them.

Could someone please see what the issue is with the code below:

<?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:background="@color/dark_background"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:padding="15dp"
    tools:layout_width="500dp"
    tools:layout_height="300dp"
    >



    <!--<android.support.constraint.Guideline-->
        <!--android:id="@+id/guideline"-->
        <!--android:layout_width="0dp"-->
        <!--android:layout_height="0dp"-->
        <!--android:orientation="vertical"-->
        <!--app:layout_constraintLeft_toRightOf="@id/title"-->
        <!--app:layout_constraintRight_toRightOf="@id/title"-->
        <!--app:layout_constraintGuide_percent="0.5"-->
        <!--/>-->

    <TextView
        android:id="@+id/title"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@+id/image"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toTopOf="@+id/ic_share"
        android:ellipsize="marquee"
        android:maxLines="4"
        android:textSize="20sp"
        android:textColor="#000000"
        android:text="This is a test content title. This would be changed eventually"
        />

    <ImageView
        android:id="@+id/image"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:adjustViewBounds="true"
        android:src="@drawable/ic_logo"
        app:layout_constraintDimensionRatio="4:3"
        app:layout_constraintLeft_toRightOf="@+id/title"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintVertical_bias="0.0"

        />

</android.support.constraint.ConstraintLayout>

Upvotes: 3

Views: 735

Answers (1)

Nicolas Roard
Nicolas Roard

Reputation: 8449

Yeah, I think that's a bug. I filed it here:

https://code.google.com/p/android/issues/detail?id=248117

Upvotes: 2

Related Questions