3

I am using from app:layout_constraintVertical_weight="5"inConstraintLayout but it doesn't work.

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

    <TextView
        android:id="@+id/txtComingSoon"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="#E1E2E4"
        android:text="New Courses Starting Soon.."
        android:textColor="#747577"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_weight="5"
        android:layout_marginTop="0dp" />

    <android.support.constraint.ConstraintLayout
        android:id="@+id/constImageButtons"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="#FF9F00"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_chainStyle="packed"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintVertical_weight="5"
        android:layout_marginBottom="0dp">

        <ImageButton
            android:id="@+id/imbRegister"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:background="@null"
            android:scaleType="fitXY"
            android:src="@drawable/ic_register"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <ImageButton
            android:id="@+id/imbMedia"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:background="@null"
            android:scaleType="fitXY"
            android:src="@drawable/ic_media"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toRightOf="@+id/imbRegister"
            app:layout_constraintTop_toTopOf="parent" />

        <ImageButton
            android:id="@+id/imbWebinar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:background="@null"
            android:scaleType="fitXY"
            android:src="@drawable/ic_webinar"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toRightOf="@+id/imbMedia"
            app:layout_constraintTop_toTopOf="parent" />

        <ImageButton
            android:id="@+id/imbAboutUs"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:background="@null"
            android:scaleType="fitXY"
            android:src="@drawable/ic_about_us"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toRightOf="@+id/imbWebinar"
            app:layout_constraintTop_toTopOf="parent" />

        <ImageButton
            android:id="@+id/imbNews"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:background="@null"
            android:scaleType="fitXY"
            android:src="@drawable/ic_news"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toRightOf="@+id/imbAboutUs"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    </android.support.constraint.ConstraintLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerMouFragment"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toTopOf="@+id/constImageButtons"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/txtComingSoon"
        app:layout_constraintVertical_bias="0.0"
        app:layout_constraintVertical_weight="8" />
</android.support.constraint.ConstraintLayout>

enter image description here

I need to this :

enter image description here

I am beginner in ConstraintLayout I need to use from ConstraintLayout like weight of LinearLayout.

Cheticamp
  • 61,413
  • 10
  • 78
  • 131
  • Please attach picture of what you want to achieve. Also, not recommended to use constraintlayout inside another constraintlayout – nomag Sep 19 '17 at 11:33
  • I edited my question . –  Sep 19 '17 at 11:40
  • layout_constraintVertical_weight will control how the space will be distributed among the elements using MATCH_CONSTRAINT. Please add snapshot of what you want to achieve. – nomag Sep 19 '17 at 11:46

1 Answers1

8

try below:

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

<TextView
    android:id="@+id/txtComingSoon"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:background="#E1E2E4"
    android:text="New Courses Starting Soon.."
    android:textColor="#747577"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toTopOf="@+id/recyclerMouFragment"
    app:layout_constraintVertical_weight="1"/>

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerMouFragment"
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintBottom_toTopOf="@+id/constImageButtons"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/txtComingSoon"
    app:layout_constraintVertical_weight="8" />

<android.support.constraint.ConstraintLayout
    android:id="@+id/constImageButtons"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:background="#FF9F00"
    app:layout_constraintTop_toBottomOf="@+id/recyclerMouFragment"
    app:layout_constraintVertical_weight="1"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_chainStyle="packed"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent">

    <ImageButton
        android:id="@+id/imbRegister"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:background="@null"
        android:scaleType="fitXY"
        android:src="@mipmap/ic_launcher"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageButton
        android:id="@+id/imbMedia"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:background="@null"
        android:scaleType="fitXY"
        android:src="@mipmap/ic_launcher"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toRightOf="@+id/imbRegister"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageButton
        android:id="@+id/imbWebinar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:background="@null"
        android:scaleType="fitXY"
        android:src="@mipmap/ic_launcher"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toRightOf="@+id/imbMedia"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageButton
        android:id="@+id/imbAboutUs"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:background="@null"
        android:scaleType="fitXY"
        android:src="@mipmap/ic_launcher"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toRightOf="@+id/imbWebinar"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageButton
        android:id="@+id/imbNews"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:background="@null"
        android:scaleType="fitXY"
        android:src="@mipmap/ic_launcher"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toRightOf="@+id/imbAboutUs"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

Shweta Chauhan
  • 6,739
  • 6
  • 37
  • 57