2016-04-07 8 views
0

Ich habe dieses Layout.Probleme in GridView Layout in Android

<?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.example.anandvardhan.albumview040416.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> 

    <GridView xmlns:android="http://schemas.android.com/apk/res/android" 
       android:id="@+id/grid_view" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:numColumns="2" 
       android:gravity="center" 
       android:background="#fff"> 
    </GridView> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|end" 
     android:layout_margin="@dimen/fab_margin" 
     android:src="@android:drawable/ic_dialog_email"/> 

</android.support.design.widget.CoordinatorLayout> 

Aber jetzt bin ich eine Vorschau wie diese bekommen:

But now I am getting a preview like this:

Wie ein Element an der Position 1 zu wählen, weil sie unterhalb der Symbolleiste sein muss.

Und noch etwas.

Wenn mein GridView anfänglich leer ist, muss es einen TextView in der Mitte des Bildschirms anzeigen, der besagt "es ist leer". Wie man es dynamisch einstellt.

Ich werde sehr dankbar sein, wenn jemand helfen könnte.

+0

Geben Sie Ihren Code ein. – Aks4125

+0

Versuchen Sie, 'GridView' Element an Position 1 in' XML' zu erreichen? – Aks4125

+0

@ Aks4125: Standardmäßig sollte es nur von Punkt 1 beginnen. Aber in der Vorschau zeigt es von Artikel 3. –

Antwort

0

Sag mir, wenn Sie Fragen haben,

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:orientation="vertical" 
    tools:context="com.example.anandvardhan.albumview040416.MainActivity"> 

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

     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true" 
     > 

     <android.support.design.widget.AppBarLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

     </android.support.design.widget.AppBarLayout> 

     <GridView android:id="@+id/grid_view" 
        xmlns:android="http://schemas.android.com/apk/res/android" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:background="#fff" 
        android:gravity="center" 
        android:numColumns="2"> 
     </GridView> 

     <android.support.design.widget.FloatingActionButton 
      android:id="@+id/fab" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom|end" 
      android:layout_margin="@dimen/fab_margin" 
      android:src="@android:drawable/ic_dialog_email"/> 

    </android.support.design.widget.CoordinatorLayout> 

</LinearLayout> 
+0

Wirklich Danke Man. Du hast meinen Tag gerettet. –

+0

@AnandVardhan kein Problem. =) – Aspicas

0

Verwenden RecyclerView und stellen Layout Manager als GridLayoutManager.

Hier ist der xml

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

<?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.example.anandvardhan.albumview040416.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> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recyclerView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingTop="@dimen/activity_vertical_margin" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 

<!-- Your Empty view here --> 

    <android.support.design.widget.FloatingActionButton 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|end" 
     android:layout_marginBottom="20dp" 
     android:layout_marginRight="20dp" 
     app:backgroundTint="@color/button_background_dark_red" 
     android:src="@drawable/ic_action_new" 
     app:borderWidth="0dp" 
     app:elevation="6dp" 
     app:fabSize="normal"/> 

</android.support.design.widget.CoordinatorLayout> 

verwenden GridLayoutManager mit RecyclerView, überprüfen Sie bitte, this site

Wenn es keine Daten gibt, können Sie die Sichtbarkeit von RecyclerView zu View.GONE eingestellt und die Sichtbarkeit der leeren Ansicht verwenden View.VISIBLE

+0

Danke, ich werde dies versuchen und Sie so schnell wie möglich benachrichtigen. –