GridLayout Not Displaying Last Column

Nathan Sokalski 4,111 Reputation points
2021-11-03T02:23:51.717+00:00

I have a layout that contains a GridLayout with 3 columns. However, it refuses to display the last column. My current code shows the following in the designer (the blue & orange areas are RecyclerViews):

145906-screenshot-2021-11-02-215327.png

My last (3rd, which is a GridLayout) column is not displayed. If I swap the layout_column values of the 2nd & 3rd columns, I get the following:

145840-screenshot-2021-11-02-215556.png

As you can see, it still shows only (what is now) the 2nd column. Also, notice that in the first screenshot, the gray rectangle at the bottom (which is a FrameLayout with a layout_columnSpan of 3) goes offscreen, while in the second one, it fits, even though no code in that View is changed. If I remove the GridLayout completely, everything looks good (except for the fact that I do not have everything I need in my layout!). The RecyclerViews (the blue & orange areas) have layout_columnWeight="1" & layout_width="0dp", and it looks to me like it is calculating their width before laying out the GridLayout in the 3rd column, but I am not sure how to fix that. What is the problem? Thanks.

Developer technologies .NET Xamarin
0 comments No comments
{count} votes

Accepted answer
  1. JarvanZhang 23,971 Reputation points
    2021-11-04T03:15:43.543+00:00

    Hello njsokalski,​

    Welcome to our Microsoft Q&A platform!

    How do you define the layout.xml? Could you please post the related code? I create a basic demo to test the function, it works as expected. Here is the sample code, you could refer to it.

       <GridLayout  
           android:rowCount="1"  
           android:columnCount="3"  
           android:layout_width="match_parent"  
           android:layout_height="match_parent">  
         
           <!--the first column-->  
           <TextView  
               android:text="the first column"  
               android:layout_row="0"  
               android:layout_column="0"  
               android:layout_width="wrap_content"  
               android:layout_height="wrap_content"/>  
         
           <!--the second column-->  
           <androidx.recyclerview.widget.RecyclerView  
               android:layout_row="0"  
               android:layout_column="1"  
               android:layout_columnWeight="1"  
                     
               android:background="#ff00"  
               android:id="@+id/recyclerView1"  
               android:layout_width="0dp"  
               android:layout_height="match_parent"/>  
         
           <!--the third column-->  
           <GridLayout  
               android:background="#ff0"  
               android:layout_row="0"  
               android:columnCount="1"  
               android:layout_column="2"  
               android:rowCount="2"  
               android:layout_width="wrap_content"  
               android:layout_height="match_parent">  
               <!--the content-->  
           </GridLayout>  
         
       </GridLayout>  
    

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.