1

The Fragment does not start below the title bar; instead the title bar overlaps the fragment(gridview)

MainActivity:

public class MainActivity extends AppCompatActivity {@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);  setSupportActionBar(toolbar);
           if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.container, new MoviesFragment())
                .commit();
    }}

activity_main.xml:

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

fragment_main:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="50dp"
android:paddingBottom="0dp"

android:id = "@+id/linearlayout">

<GridView android:id = "@+id/gridview"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"

    android:layout_weight="1"
    android:padding="0dp"
    android:verticalSpacing="0dp"
    android:horizontalSpacing="0dp"
    android:numColumns="auto_fit"
    android:stretchMode="columnWidth"
    android:background="#000000"
    >

</GridView>

Note: I tried adding a padding to the top of the fragment, but on change of orientation, the gap becomes visible again.

Siddharth Sharma
  • 182
  • 1
  • 1
  • 10

0 Answers0