1

I have a recycler view with a custom adapter and i am displaying news in recycler view. its working perfectly but its showing like given screen shots. I need code example step by step. how can i acheive that. My code of custom xml for recycler view.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#30000000">

<ImageView
    android:id="@+id/iv_news"
    android:layout_width="match_parent"
    android:layout_height="160dp" />
<TextView
    android:id="@+id/tv_news_title"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColor="@color/black"
    android:layout_marginTop="5dp"
    android:padding="5dp"
    android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
    />
</LinearLayout>

screen shot now displaying like this enter image description here

but i want to display it like this enter image description here

Asif Ullah
  • 61
  • 14
  • 1
    So there'll be one item then 2 items in same row and then 1 single item again? And this will keep repeating? – denvercoder9 Nov 24 '17 at 15:21
  • Possible duplicate of [How to create RecyclerView with multiple view type?](https://stackoverflow.com/questions/26245139/how-to-create-recyclerview-with-multiple-view-type) – denvercoder9 Nov 24 '17 at 15:24

1 Answers1

0

You need to set the orientation of your linear layout horizontal instead of vertical on your linear layout above.android:orientation="horizontal", specify the width in dp rather than match_parent for the image view and text view

`

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#30000000">

<ImageView
android:id="@+id/iv_news"
android:layout_width="50dp"
android:layout_height="160dp" /> 

<TextView
android:id="@+id/tv_news_title"
android:layout_width="wrap_ content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:layout_marginTop="5dp"
android:padding="5dp"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
/>

</LinearLayout>

`

Demilade
  • 513
  • 2
  • 7