• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Android Studio 2.2.2 GridLayout does not work

I am not designing this in my code, I am using the layout design editor. When I drag the GridLayout component on to the screen it does not show the co-ordinates and it does not mark the columns or the rows with the green bars. It is not working the way it should. Is there a setting that I am not enabling? Please help as I am going through a Tutorial and am stuck at this point.
 
It's not really a show stopper is it? If you drag a component to the GridLayout, it should tell you where the component is going to be placed. And it's pretty easy to move components if they don't land at the location you intended.
 
It's not really a show stopper is it? If you drag a component to the GridLayout, it should tell you where the component is going to be placed. And it's pretty easy to move components if they don't land at the location you intended.
Well It does not allow me to add a button in the GridLayout therefore stops me dead in my tracks
 
Strange. Do you have a screenshot of what the design editor looks like after you've added the Gridlayout?
 
Also, what does the layout XML look like? Can you post it here?
 
Also, what does the layout XML look like? Can you post it here?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.papab.gridlayout.MainActivity">

<GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="9dp">

</GridLayout>

<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:id="@+id/button"/>
</RelativeLayout>
 
Strange. Do you have a screenshot of what the design editor looks like after you've added the Gridlayout?
Yes here is a corel paint screen shot
gridlayout.jpg
 
Well as it stands, your Button is not in the GridLayout. You know that you can edit the XML text, and move the Button definition inside the GridLayout, like this

Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.papab.gridlayout.MainActivity">

<GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="9dp">

<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:id="@+id/button"/>

</GridLayout>

</RelativeLayout>
 
And you also have a superfluous <RelativeLayout>. Your <GridLayout> should be the root element. So I would say ditch the RelativeLayout.
 
Well as it stands, your Button is not in the GridLayout. You know that you can edit the XML text, and move the Button definition inside the GridLayout, like this

Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.papab.gridlayout.MainActivity">

<GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="9dp">

<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:id="@+id/button"/>

</GridLayout>

</RelativeLayout>
Well as it stands, your Button is not in the GridLayout. You know that you can edit the XML text, and move the Button definition inside the GridLayout, like this

Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.papab.gridlayout.MainActivity">

<GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="9dp">

<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:id="@+id/button"/>

</GridLayout>

</RelativeLayout>
And you also have a superfluous <RelativeLayout>. Your <GridLayout> should be the root element. So I would say ditch the RelativeLayout.
Well as it stands, your Button is not in the GridLayout. You know that you can edit the XML text, and move the Button definition inside the GridLayout, like this

Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.papab.gridlayout.MainActivity">

<GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="9dp">

<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:id="@+id/button"/>

</GridLayout>

</RelativeLayout>
 
Yes thank you very much, but my question still remains why does my layout designer in Android Studio not 1. in design mode not place button in gridlayout 2. why should I remove the relativelayout tags. The tutorial doesn't have to use this coding work around
 
1. You probably didn't drag the Button component on to the GridLayout (it's pretty small if you use wrap_content as width and height)
2. What tutorial are you using? The one below does not have an extra <RelativeLayout>

http://www.techotopia.com/index.php/Working_with_the_Android_GridLayout_in_XML_Layout_Resources

Both GridLayout and RelativeLayout are containers, into which you place other components. They just differ in the way that the components are placed relative to each other.
There's nothing stopping you having a GridLayout in a RelativeLayout, but it only makes sense if you have something else inside the RelativeLayout. Otherwise it's merely a container for a single GridLayout. Like I said, unnecessary.
 
1. You probably didn't drag the Button component on to the GridLayout (it's pretty small if you use wrap_content as width and height)
2. What tutorial are you using? The one below does not have an extra <RelativeLayout>

http://www.techotopia.com/index.php/Working_with_the_Android_GridLayout_in_XML_Layout_Resources

Both GridLayout and RelativeLayout are containers, into which you place other components. They just differ in the way that the components are placed relative to each other.
There's nothing stopping you having a GridLayout in a RelativeLayout, but it only makes sense if you have something else inside the RelativeLayout. Otherwise it's merely a container for a single GridLayout. Like I said, unnecessary.
 
Back
Top Bottom