'layout_columnWeight and layout_rowWeight different size elements

I'm interested to know how the parameters are distributed app:layout_columnWeight="1" app:layout_rowWeight="1"

do these parameters change only in height? Or on all sides?

why in my case with the same size of 6 top buttons, all text have one size the bottom two buttons are smaller?

because I have margin offset?

What is better in this case, to use xml layout or software, written in the mainactivity file in Java? gridLayout



Solution 1:[1]

Sorry I'm newbee in android studio, as I understand, if I use RelativeLayout and GridLayout, then when using parameters:

 app:layout_columnWeight="1"
 app:layout_rowWeight="1"
 android:layout_width="0dp"
 android:layout_height="wrap_content"
 app:layout_gravity="fill"
 and match_parent

With such xml parameters, I can only get buttons to automatically expand depending on the length of the text? Then what type configuration I need for the same result, only for button heights to be the same and scalable, or is there anyway I'll get the button offset if I don't respect the more uniform text length on Button?

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_alignParentEnd="true"
    android:padding="4dp">
    tools:context=".MainActivity">

    <androidx.gridlayout.widget.GridLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginStart="4dp"
        android:layout_marginTop="4dp"
        android:layout_marginEnd="4dp"
        android:layout_marginBottom="4dp"
        android:textSize="10sp">

        <Button
            android:id="@+id/text1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginRight="5dp"
            android:text="Text"
            app:layout_column="0"
            app:layout_columnWeight="1"
            app:layout_gravity="fill"
            app:layout_row="0"
            app:layout_rowWeight="1"
            android:onClick="buttonTapped"/>

        <Button
            android:id="@+id/text2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:text="Text Text"
            app:layout_column="1"
            app:layout_row="0"
            app:layout_gravity="fill"
            app:layout_columnWeight="1"
            app:layout_rowWeight="1"
            android:onClick="buttonTapped"/>

        <Button
            android:id="@+id/text3"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginRight="5dp"
            android:text="TextText Text"
            app:layout_column="0"
            app:layout_columnWeight="1"
            app:layout_gravity="fill"
            app:layout_row="1"
            app:layout_rowWeight="1"
            android:onClick="buttonTapped"/>

        <Button
            android:id="@+id/text4"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:text="Text"
            app:layout_column="1"
            app:layout_columnWeight="1"
            app:layout_gravity="fill"
            app:layout_row="1"
            app:layout_rowWeight="1"
            android:onClick="buttonTapped"/>

        <Button
            android:id="@+id/text5"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginRight="5dp"
            android:text="Text Text Text"
            app:layout_column="0"
            app:layout_columnWeight="1"
            app:layout_gravity="fill"
            app:layout_row="2"
            app:layout_rowWeight="1"
            android:onClick="buttonTapped"/>

        <Button
            android:id="@+id/text6"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:text="TextText TextText Text"
            app:layout_column="1"
            app:layout_columnWeight="1"
            app:layout_gravity="fill"
            app:layout_row="2"
            app:layout_rowWeight="1"
            android:onClick="buttonTapped"/>

        <Button
            android:id="@+id/text7"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginRight="5dp"
            android:text="TextText"
            app:layout_column="0"
            app:layout_columnWeight="1"
            app:layout_gravity="fill"
            app:layout_row="3"
            app:layout_rowWeight="1"
            android:onClick="buttonTapped"/>

        <Button
            android:id="@+id/text8"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:text="TextTextText"
            app:layout_column="1"
            app:layout_columnWeight="1"
            app:layout_gravity="fill"
            app:layout_row="3"
            app:layout_rowWeight="1"
            android:onClick="buttonTapped"/>

    </androidx.gridlayout.widget.GridLayout>
</RelativeLayout>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 formasters777