I created a action bar in xml for use in all activities. I used the include tag for it.
One of my activities have just a GridView tag. you can see it’s source below:
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gv_level"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@drawable/background_gradient"
android:columnWidth="100dp"
android:gravity="center"
android:numColumns="auto_fit"
android:stretchMode="columnWidth" >
</GridView>
It doesn’t have any problem but when I add the include tag or any other tag to this (similar below source)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
layout="@layout/action_bar" />
<GridView
android:id="@+id/gv_level"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@drawable/background_gradient"
android:columnWidth="100dp"
android:gravity="center"
android:numColumns="auto_fit"
android:stretchMode="columnWidth" >
</GridView>
It doesn’t give me an error but the GridView is hidden when the activity appears.
Is there a solution for this problem?
You may want to either set the orientation of the
LinearLayoutto vertical so your included layout doesn’t push theGridViewoutside of the screen on the right or you could usewrap_contentfor the included layout’s width. Using the orientation change: