2016-04-07 3 views
0

У меня есть этот макет.Возникли проблемы с маской GridView в 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> 

Но теперь я получаю предварительный просмотр, как это:

But now I am getting a preview like this:

Итак, как выбрать элемент в положении 1, потому что она должна быть ниже на панели инструментов.

И еще одно.

Если мой GridView изначально пуст, он должен показать TextView в центре экрана с надписью «It is Empty». Как установить его динамически.

Буду очень благодарен, если кто-нибудь сможет помочь.

+0

Отправьте свой код. – Aks4125

+0

Вы пытаетесь достичь элемента 'GridView' в позиции 1 в' XML'? – Aks4125

+0

@ Aks4125: По умолчанию он должен начинаться только с пункта 1. Но в предварительном просмотре он показывает из пункта 3. –

ответ

0

Скажите мне, если у вас есть какие-либо вопросы,

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

Действительно, спасибо человеку. Ты спас свой день. –

+0

@AnandVardhan проблем нет. =) – Aspicas

0

Использование RecyclerView и установить Layout Manager в GridLayoutManager.

Вот 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> 

Чтобы использовать GridLayoutManager с RecyclerView, пожалуйста, проверьте this site

Если нет никаких данных, вы можете установить видимость RecyclerView для View.GONE и установить видимость пустого зрения to View.VISIBLE

+0

Спасибо, я попробую это и уведомит вас как можно скорее. –

Смежные вопросы