Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto-fit items in Linear layout

I have two constraint layouts in a linear layout. I want the constraint layouts to occupy 30% and 70% of the screen respectively on all devices. What attribute inside the Linear Layout do I need to set in order to achieve this?

like image 988
Ishaan Ohri Avatar asked Feb 21 '26 18:02

Ishaan Ohri


1 Answers

This should give the desired result. Setting a weightSum attribute to the parent linear layout and then accordingly giving the weights helps

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

        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.3"/>

        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.7"/>
</LinearLayout>
like image 152
Akanshi Srivastava Avatar answered Feb 24 '26 10:02

Akanshi Srivastava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!