1

I want to show a gridview inside a fragment ,In my case I have toolbar in fragment ,when I tried to show the gridview it shows over the toolbar . Please help me to solve this .

Xml code

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:id="@+id/reminders_Fragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Fragments.Reminders">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_weight="1"
        android:background="@color/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/AppTheme.PopupOverlay"
        app:title="Reminders"
        app:titleTextColor="@color/tab_background">

    </android.support.v7.widget.Toolbar>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <GridView xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/photogridview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:adjustViewBounds="true"
            android:columnWidth="90dp"
            android:gravity="center"
            android:horizontalSpacing="10dp"
            android:numColumns="3"
            android:stretchMode="spacingWidthUniform"
            android:verticalSpacing="45dp"></GridView>
    </LinearLayout>
</FrameLayout>
Nikson
  • 900
  • 2
  • 21
  • 51
  • 1
    That's just how `FrameLayout` works. It'll stack its children one atop the other. You should change that to a `LinearLayout`, and set its `orientation` to `vertical`. `LinearLayout` doesn't overlap its children. That inner `LinearLayout` you currently have is pointless, btw. – Mike M. Apr 18 '18 at 23:17
  • @MikeM. can you please help me to fix this issue https://stackoverflow.com/questions/49957819/gridview-and-it-is-images-are-not-automatically-fit-for-all-the-screen-sizes – Nikson Apr 22 '18 at 05:42
  • You've deleted it. – Mike M. Apr 22 '18 at 06:32
  • Oh, and you just reposted it. Don't do that. Furthermore, how is it any different than https://stackoverflow.com/q/49944627, where you accepted the answer? – Mike M. Apr 22 '18 at 06:33
  • @MikeM. please take a look at this https://stackoverflow.com/questions/49963179/gridview-is-not-fit-for-all-screens-in-android – Nikson Apr 22 '18 at 06:33

1 Answers1

1
**Add android:layout_marginTop="?android:actionBarSize" in GridView.**

<?xml version="1.0" encoding="utf-8"?>

<FrameLayoutxmlns: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:id="@+id/reminders_Fragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_weight="1"
            android:background="@color/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/AppTheme"
            app:title="Reminders"
            app:titleTextColor="@color/colorAccent">

        </android.support.v7.widget.Toolbar>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <GridView xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_marginTop="?android:actionBarSize"
                android:id="@+id/photogridview"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:adjustViewBounds="true"
                android:columnWidth="90dp"
                android:gravity="center"
                android:horizontalSpacing="10dp"
                android:numColumns="3"
                android:stretchMode="spacingWidthUniform"
                android:verticalSpacing="45dp"></GridView>

        </LinearLayout>

    </FrameLayout>

For Different Screens : enter image description here enter image description hereenter image description here

Nikson
  • 900
  • 2
  • 21
  • 51
Kaushal Gosaliya
  • 421
  • 7
  • 16