How to Adjust View Width and Height using ConstraintLayout Percent Values in Android

In this android programming source code example, we are going to explore how to adjust view width and height using ConstraintLayout percent values in android.

Below is a step by step source code to adjust view width and height using ConstraintLayout percent values in android.

activity_layout15.xml

<?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"
    tools:context=".layout.Layout15">

    <Button
        android:id="@+id/button7"
        android:layout_width="0dp"
        app:layout_constraintWidth_percent="0.7"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:text="Button"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <CalendarView
        android:id="@+id/calendarView"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        app:layout_constraintHeight_percent="0.8"
        android:layout_marginStart="16dp"
        android:layout_marginLeft="16dp"
        android:layout_marginBottom="63dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent" />
    
</android.support.constraint.ConstraintLayout>

Layout15.java

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class Layout15 extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_layout15);
    }
}

If you have any question or suggestions kindly use the comment box or you can contact us directly through our contact page below.

 

Add a Comment