0

Actually I want to make a grid View with limited item such that there should be two items in a row and there should be proper spacing between them .In Grid view ,I have used android:stretchMode="spacingWidthUniform"> but now there is no such option. I need a default function that should work in all situations. i.e one at one corner ,other at differnt corner with some padding and margins.

Here is the code of single grid

<android.support.v7.widget.CardView
android:id="@+id/cardView"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
app:cardCornerRadius="20dp"
app:cardElevation="@dimen/activity_vertical_margin"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">


<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/vehicle_selection_single_item_layout"
    android:layout_width="100dp"
    android:layout_height="150dp"
    android:orientation="vertical"
    android:layoutMode="clipBounds"
    android:padding="5dp">
    <ImageView
        android:id="@+id/single_item_image_view"
        android:src="@drawable/car"
        android:layout_width="match_parent"
        android:layout_height="100dp" />
    <TextView
        android:id="@+id/single_item_text_view"
        android:layout_width="100dp"
        android:layout_height="50dp"
        android:text="Car"
        android:textSize="15sp"
        android:layout_marginStart="2dp"
        android:textStyle="bold"
        android:textColor="@color/navy_blue"/>
</RelativeLayout>
</android.support.v7.widget.CardView>

Image Link

RisingSun
  • 3
  • 7
  • You directly specify the number of rows or number of columns based on horizontal or vertical scrolling list. – Mohammed Atif Jan 28 '17 at 02:33
  • http://stackoverflow.com/questions/28531996/android-recyclerview-gridlayoutmanager-column-spacing – Mohammed Atif Jan 28 '17 at 02:34
  • http://stackoverflow.com/questions/31171135/recyclerview-grid-define-number-of-items-per-row-in – Mohammed Atif Jan 28 '17 at 02:35
  • As in the first link, give match parent to width and use ItemDecoration to give the spacing. P.S. Grid resizes your view to meets it contract. So no matter you specify 100dp of 500dp, Grid will render it according to ItemDecoration only. – Mohammed Atif Jan 28 '17 at 02:38
  • you have to use gridlayoutmanager with your recyclerview and then specify the span size – masoud vali Jan 28 '17 at 04:05
  • @MohammedAtif In the first link they define the spacing manually .I need something like android:stretchMode="spacingWidthUniform">,so that both the span that are in same row should adjust themselves at the corner regardless of the phone size in portrait mode – RisingSun Jan 28 '17 at 08:06
  • @masoudvali Added Image link – RisingSun Jan 28 '17 at 08:15
  • @RisingSun Can you please update your code where you are initializing relative layout and also your relative layout xml – Mohammed Atif Jan 28 '17 at 13:51
  • @MohammedAtif I have solved that problem by using Item Decorator.Now i am facing problem regarding handling of this span .As getPosition() method is deprecated .Kindly suggest a new method ,so that i can handle these events properly – RisingSun Jan 28 '17 at 19:16

0 Answers0