2015-11-26 2 views
0

Я хочу, чтобы настроить GridView layout.I хочет GridView выглядеть снимок, представленный ниже: -Как настроить GridView в Android

App Example

Вот мой GridView макет: -

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:padding="15dp" 
    android:background="#fff"> 

    <ImageView 
     android:id="@+id/image_grid_view" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/ic_action_name" 
     android:layout_gravity="center"/> 

    <TextView 
     android:id="@+id/product_id_grid_view" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:visibility="gone" /> 


    <TextView 
     android:id="@+id/product_name_grid_view" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="test" 
     android:paddingLeft="10dp" 
     android:textSize="15dp" 
     android:textColor="@color/divder_color"/> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

     <TextView 
      android:id="@+id/product_discount_grid_view" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textColor="@android:color/black" 
      android:paddingLeft="10dp" 
      android:text="1891" /> 

     <TextView 
      android:id="@+id/product_special_grid_view" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textColor="@android:color/black" 
      android:text="1891" 
      android:paddingLeft="10dp" /> 

     <TextView 
      android:id="@+id/products_price_grid_view" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="8dp" 
      android:textColor="@android:color/darker_gray" 
      android:paddingLeft="5dp" /> 

     <TextView 
      android:id="@+id/products_off_grid_view" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="20" 
      android:textSize="8dp" 
      android:textColor="@android:color/holo_red_dark" 
      android:paddingLeft="5dp"/> 

    </LinearLayout> 


    <RatingBar 
     android:id="@+id/ratingBar_grid_view" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:numStars="5" 
     style="?android:attr/ratingBarStyleSmall" 
     android:rating="0" /> 

</LinearLayout> 

Вот мой макет, в котором я получить доступ к GridView: -

<GridView 
      android:id="@+id/list_product_grid" 
      android:layout_width="fill_parent" 
      android:layout_height="match_parent" 
      tools:listitem="@layout/products_page_grid_view" 
      android:numColumns="2" 
      android:horizontalSpacing="2dp" 
      android:gravity="center" 
      android:background="#fff" 
      android:padding="10dp" 
      android:visibility="visible" 
      android:verticalSpacing="2dp"/> 

Может кто-нибудь поможет мне, как я делаю свой GridView похожим на изображение выше. Я новичок в Android. Пожалуйста, помогите мне. Спасибо заранее.

ответ

0

Создать класс расширяет BaseAdapter и раздуть макет XML для каждой строки в getView и установить data.You может передать этот: https://www.caveofprogramming.com/guest-posts/custom-gridview-with-imageview-and-textview-in-android.html, не такой же, как вы хотите, но я думаю, что вы будете знать, как это сделать, как вы хотите после прочтения этого.

Я предлагаю вам использовать RecyclerView вместо GridView, который имеет более эффективные характеристики и гибкие менеджеры макетов.

+0

Какой ссылку на этой странице вы мне это не найдено. –

0

Вы можете следить за GridLayoutManager с RecyclerView для создания пользовательского интерфейса, который вы показаны в ссылке, и она будет более гибкой, чтобы сделать какую-либо соответствующую операцию, такими как добавление, удаление элементов и т.д. RecyclerView имеет встроенные анимации и нет необходимости беспокоиться о повторном использовании view too.you может потребоваться использовать CardView как элемент сетки.

Выполните любое из учебника, чтобы добиться того, что

Link 1

Link 2

Link 3

Link 4

Найти использование выборки CardView along with RecyclerView.

0

попробовать этот код для grid_item_layout путем замены вашего вводимого коэффициента,

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_margin="10dp" 
    android:orientation="vertical" 
    android:padding="15dp"> 

    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <ImageView 
      android:id="@+id/image_grid_view" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:src="@drawable/"your product drawable name"/> 

     <TextView 
      android:id="@+id/new_text_view" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignBottom="@id/image_grid_view" 
      android:background="#666666" 
      android:text="New" 
      android:textColor="#000000" 
      android:textSize="15sp"/> 

     <ImageButton 
      android:id="@+id/bookmark_text_view" 
      android:layout_width="30dp" 
      android:layout_height="30dp" 
      android:layout_alignRight="@id/image_grid_view" 
      android:layout_alignTop="@id/image_grid_view" 
      android:src="@drawable/your bookmark or favourite drawable name" 
      android:textColor="#000000" 
      android:textSize="15sp"/> 
    </RelativeLayout> 

    <TextView 
     android:id="@+id/product_id_grid_view" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="TOPSHOP"/> 


    <TextView 
     android:id="@+id/product_name_grid_view" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:paddingLeft="10dp" 
     android:text="Rs.3990" 
     android:textColor="#ff0000" 
     android:textSize="15dp"/> 
</LinearLayout> 
Смежные вопросы