-1

I am creating a android app where i need to display blog post in recycler-view / card-view grid like attached any examples or suggestion?

enter image description here

or like this one

enter image description here

or like this ?

enter image description here

Ashfaque Ali Solangi
  • 1,883
  • 3
  • 22
  • 34

1 Answers1

0

Grid View Example

I hope this screenshot of my app is a bit close to what you want as shown in your 3rd screenshot. I will show you my source code just for you get an idea.

LAYOUT.XML File This is the layout File

<LinearLayout
    android:id="@+id/layer"
    android:gravity="right"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

<Button
    android:id="@+id/addBttn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="+"/>

    <Button
        android:id="@+id/doneBttn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Done"/>
</LinearLayout>

<GridView
    android:layout_below="@id/layer"
    android:id="@+id/gridView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="5dp"
    android:gravity="center"
    android:numColumns="auto_fit"
    android:focusable="true"
    android:clickable="true"/>**

This is the ADAPTER Class used to fill in the data to GridView

Then you can set the Adapter created to your grid view like this from any of your Activities

public class gridViewAdapter extends BaseAdapter{
private Context context;
private View view;
private LayoutInflater layoutInflater;
private final ArrayList<Uri> Images;

public gridViewAdapter(@NonNull Context context,ArrayList<Uri>images) {
    this.context = context;
    Images = images;
}


@Override
public int getCount() {
    return Images.size();
}

@Override
public Object getItem(int position) {
    return null;
}

@Override
public long getItemId(int position) {
    return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    if(convertView == null) {
        view = new View(context);
        view = layoutInflater.inflate(R.layout.grid_item_layout,null);
        ImageView imageView =     (ImageView)view.findViewById(R.id.imageView1);
        imageView.setImageURI(Images.get(position));

    }
    return view;
}

}

gridView =(GridView) this.findViewById(R.id.gridView);
    gridViewAdapter gridAdapter = new gridViewAdapter(this,imgUriList);
    gridView.setAdapter(gridAdapter);
jhashane
  • 774
  • 1
  • 9
  • 17