Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GridLayout from support library does not show 2 rows on Android 2, onChildVisibilityChanged Error

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>
like image 417
Beth Mezias Avatar asked May 21 '12 06:05

Beth Mezias


People also ask

What is the difference between GridLayout and GridView?

Let us not get confused with GridView and GridLayout to be the same. GridView simply gives us a two-dimensional view to display the items on the screen, under ViewGroup. On the other hand, GridLayout is a layout manager that arranges the views in a grid.

What is GridLayout Android studio?

android.widget.GridLayout. A layout that places its children in a rectangular grid. The grid is composed of a set of infinitely thin lines that separate the viewing area into cells. Throughout the API, grid lines are referenced by grid indices.

What do you use a GridLayout for in an app?

GridLayout allows you to place many views and elements inside the layout and then style them. It allows you to set the number of rows and columns for your grid.

What is GridLayout spec?

android.widget.GridLayout.Spec. A Spec defines the horizontal or vertical characteristics of a group of cells. Each spec. defines the grid indices and alignment along the appropriate axis. The grid indices are the leading and trailing edges of this cell group.


1 Answers

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...

like image 85
Tomáš Hubálek Avatar answered Sep 30 '22 11:09

Tomáš Hubálek