skip to Main Content

enter image description here

Two text views are not visible some ways to fix it is giving end margin, remove the icon or wrap it with frame layout. I’m not able to understand what is causing this issue and which is the better way to fix it? I know constraint layout is better but I was learning grid layout and found this issue.

<GridLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/gridLayoutLoremIpsum"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:columnCount="2"
    android:rowCount="3"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_user_image" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_user_image"
        android:text="@string/dummy_text_sentence_short" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_user_image" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/dark_gray_hint"
        android:text="@string/dummy_text_sentence_short" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_columnSpan="2"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        android:text="Next" />
</GridLayout>

2

Answers


  1. "wrap_layout" makes it out of bound. Just write match_parent and it makes full width and it will not be out of bound.
    if you use wrap_content and lets say that layout width is 100 and your text is so long and there should be 150dp width to fit text into that textview, your textview will be 150 instead of 100. wrap_content does not make new line. it is stright forward, one line.
    So, using match_parent will solve your problem

    if it will work as you want, please mark as accepted answer.

    Thanks

    Login or Signup to reply.
  2. Try this,

    <GridLayout
        android:id="@+id/gridLayoutLoremIpsum"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:columnCount="6"
        android:rowCount="3"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">
    
        <ImageView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_row="0"
            android:layout_columnWeight="1"
            android:src="@drawable/ic_user_image" />
    
        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_row="0"
            android:layout_columnSpan="5"
            android:layout_columnWeight="5"
            android:src="@drawable/ic_user_image"
            android:text="@string/dummy_text_sentence_short" />
    
        <ImageView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_columnWeight="1"
            android:src="@drawable/ic_user_image" />
    
        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_columnSpan="5"
            android:layout_columnWeight="5"
            android:background="@color/white"
            android:text="@string/dummy_text_sentence_short" />
    
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_columnSpan="5"
            android:layout_marginStart="8dp"
            android:layout_marginEnd="8dp"
            android:text="Next" />
    </GridLayout>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search