I want the textView to occupy all the width without modifying the rest

1

I need the following code to have a layout and the textView to occupy all the width but without deforming the buttons below, which must belong to the second column intact.

<GridLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:useDefaultMargins="true">


    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="0"
        android:layout_margin="5dp"
        android:layout_row="0"
        android:background="@android:color/black"
        android:text="TextView"
        android:textColor="@android:color/holo_blue_dark"
        android:textSize="30dp"
        tools:layout_editor_absoluteX="62dp"
        tools:layout_editor_absoluteY="25dp"
        />

    <Button
        android:id="@+id/button5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="0"
        android:layout_row="1"
        android:text="Button" />

    <Button
        android:id="@+id/button8"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="1"
        android:layout_row="1"
        android:text="Button" />

    <Button
        android:id="@+id/button9"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="2"
        android:layout_row="1"
        android:text="Button" />

    <Button
        android:id="@+id/button10"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="3"
        android:layout_row="1"
        android:text="Button" />
</GridLayout>
   

    
asked by Fausto Jeje 04.06.2018 в 19:39
source

1 answer

0

You are currently defined for TextView with id textView3 :

    android:layout_width="wrap_content"

change to:

     android:layout_width="match_parent"

so that it takes the full width of the parent container.

but now there is a problem the buttons move to the right, what you should now define is a span that spans 4 columns, for this you now use the property android: layout_columnSpan .

  

android: layout_columnSpan : The column stretch: the difference   between the right and left limits that delimit the group of cells   occupied by this view.

android:layout_columnSpan="4" .

In this way, your TextView would cover the entire width that would be 4 columns of your GridLayout and would be displayed in this way:

This would be the layout:

<?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"
    android:background="@android:color/darker_gray"
    tools:context=".MainActivity">

    <GridLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:useDefaultMargins="true">


        <TextView
            android:id="@+id/textView3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_columnSpan="4"
            android:layout_column="0"
            android:layout_margin="5dp"
            android:layout_row="0"
            android:background="@android:color/black"
            android:text="TextView"
            android:textColor="@android:color/holo_blue_dark"
            android:textSize="30dp"
            tools:layout_editor_absoluteX="62dp"
            tools:layout_editor_absoluteY="25dp"/>

        <Button
            android:id="@+id/button5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="0"
            android:layout_row="1"
            android:text="Button" />

        <Button
            android:id="@+id/button8"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="1"
            android:layout_row="1"
            android:text="Button" />

        <Button
            android:id="@+id/button9"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="2"
            android:layout_row="1"
            android:text="Button" />

        <Button
            android:id="@+id/button10"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="3"
            android:layout_row="1"
            android:text="Button" />
    </GridLayout>

    <!-- android:id="@+id/textView6"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:background="@android:color/black"
     android:text="TextView"
     android:textColor="@android:color/holo_blue_dark"
     android:textSize="28dp"
     tools:layout_editor_absoluteX="62dp"
     tools:layout_editor_absoluteY="25dp"-->

</android.support.constraint.ConstraintLayout>
    
answered by 04.06.2018 в 20:40