Reputation: 494
I've got a GridView filled with an adapter. The display is working for every item in my gridView. But I have a problem my gridView is going under the toolbar when the main activity is displayed. Here is my code :
actyvity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.mtoy.laboiteasqueezie.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
content_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.mtoy.android.recyclerview.MainActivity"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#d6d6d6">
<GridView
android:id="@+id/list1"
android:background="#ffffff"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="auto_fit"
android:gravity="center"
android:columnWidth="150dp"
android:stretchMode="columnWidth"/>
</RelativeLayout>
items in my GridView :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:minHeight="150dp"
android:paddingBottom="6dp"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:background="#ffffff"
android:orientation="vertical"
android:layout_marginBottom="5dp">
<ImageView
android:id="@+id/icon"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:focusable="false"
android:focusableInTouchMode="false" />
<TextView
android:id="@+id/description"
android:textSize="18sp"
android:textColor="#898A8A"
android:singleLine="false"
android:textAlignment="center"
android:textStyle="italic"
android:background="#ffffff"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center" />
</LinearLayout>
I'm sure the solution must be simple but I can't figure out what it is. Can you help me with that please ?
Upvotes: 1
Views: 341
Reputation: 1229
Add this line to your Relative Layout
app:layout_behavior="@string/appbar_scrolling_view_behavior"
Upvotes: 2