10

Has anybody gotten the support library to render a grid layout correctly in Android 2? Instead of 2 rows and columns I get a single row on the screen and see this error in the logcat output: Android GridLayout Could not find method android.support.v7.widget.ViewGroup.onChildVisibilityChanged

The same exact layout is working on Android4 -> ICS when I change the layout tag from android.support.v7.widget.GridLayout to GridLayout

Could this be some issue with the setup? I have the gridlayout_v7 library project in the Android tab of my Eclipse project properties and the v.13 jar is on the build path.

The XML layout that is failing is pasted below. I added the layout rows and columns explicitly in the image button tags in an effort to work around the problem. If anybody has a working example that runs on Android 2 with the support library, please share.

<android.support.v7.widget.GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="2"  android:rowCount="2"
android:gravity="center_vertical" 
android:layout="@drawable/bg_test_main" >

<ImageButton android:id="@+id/btnSentence"
android:layout_row="0"
android:layout_column="0"
android:src="@drawable/testa_btn"
android:contentDescription="@string/spin_fill_in"
android:background="@android:color/transparent"
/>
<ImageButton android:id="@+id/btnAudio"
android:layout_row="0"
android:layout_column="1"
    android:src="@drawable/testb_btn"
android:contentDescription="@string/audio_quiz"
android:background="@android:color/transparent"
/>
<ImageButton android:id="@+id/btnPickWord"
android:layout_row="1"
android:layout_column="0"
android:src="@drawable/testc_btn"
android:background="@android:color/transparent"
android:contentDescription="@string/def_pick_word" />

<ImageButton android:id="@+id/btnPickDef"
android:layout_row="1"
android:layout_column="1"
android:src="@drawable/testd_btn"
android:background="@android:color/transparent"
android:contentDescription="@string/pick_def" />

</android.support.v7.widget.GridLayout>
ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Beth Mezias
  • 270
  • 3
  • 13

1 Answers1

37

I guess you missed to add XML namespace. Please correct it in this way:

<android.support.v7.widget.GridLayout 
     xmlns:grid="http://schemas.android.com/apk/res-auto"
     xmlns:android="http://schemas.android.com/apk/res/android">
...
</android.support.v7.widget.GridLayout>

and don't forget to prefix attributes used by compatibility GridLayout with XML namespace too:

<ImageButton android:id="@+id/btnSentence"
    grid:layout_row="0"
    grid:layout_column="0"
    ...
/>

Hope it helps...

Tomáš Hubálek
  • 1,162
  • 1
  • 10
  • 28
  • This is a great answer! Thank you Tomas! Do you have a link to any documentation? I did a lot of search before creating this post. The layout has 2 rows now. The next problem is getting the grid centered with equal margins on each side as well as the top and bottom. Do you have a fix for that too? – Beth Mezias May 21 '12 at 20:38
  • @Beth you should check this answer if he answered you – confucius May 24 '12 at 22:00
  • ah - touch the checkmark... I tried to figure that out when this answer came in. Thanks to you @Nammari – Beth Mezias May 25 '12 at 02:34
  • After adding space objects to the layout I find that gridlayout is not working as I expect. I got it to work but it is like a FrameLayout, anchored to the top right. I have reverted to weighted and nested LinearLayouts until more examples and documentation become available. – Beth Mezias Jun 01 '12 at 19:34
  • Why do I get `app:rowCount` instead of `android:rowCount` in the property for `GridLayout` ? – mr5 May 15 '14 at 03:26
  • @mr5 do you have 'xmnls:app'? – Erik B Feb 02 '15 at 23:35