I am trying to place a LinearLayout
inside the second column of a parent GridLayout
.I want a textView
in the first column and the linear layout in the second.
The problem is that when I set the LinearLayout
's with property to match_parent
, the linear layout expands with a width greater than the remaining space in the column and it and the GridLayout
overflow the screen as shown below in the picture.
I am assuming the the LinearLayout
's parent is not the GridLayout's second column therefore the match_parent key sets the width to the wisth of the whole screen(also applies to height with a property of match_parent)
I am looking for a way that the column becomes the LinearLayout
's parent so that it fills the rest of the screen in front of the textview
and I want to use the grid layout on purpose because of its advantages in design.I am also new to android so any help would be appriciated.
here's the layout code just in case :
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
android:columnCount="2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/textView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/textView2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/textView3" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="1"></LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/textView4" />
</GridLayout>
Ok so the problem was that I was trying to fill the remaining horizontal space with android:layout_width
and setting it to match_parent
.The problem with this approach is that with match parent, I am setting the width of the layout with its parent's(the grid layout) width which is as big as the whole screen, therefore it overflows the devices screen.
I should have set android:layout_gravity
to fill_horizontal
in order to achieve my goal