如何在材料cardview上填充数据

时间:2016-01-23 16:35:50

标签: android gridview tile material

我一直关注着 Google Code labs material design教程。我不确定如何更改卡片视图,因此我为每张独特的卡片都有单独的图像和文字。我该如何实现呢?

Recipes_Fragment

public static class ViewHolder extends RecyclerView.ViewHolder {

    public ViewHolder(LayoutInflater inflater, ViewGroup parent) {
        super(inflater.inflate(R.layout.fragment_recipes, parent, false));
        itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Context context = v.getContext();
                Intent intent = new Intent(context, DetailActivity.class);
                context.startActivity(intent);
            }
        });
    }
}


/**
 * Adapter to display recycler view.
 */
public static class ContentAdapter extends RecyclerView.Adapter<ViewHolder> {
    // Set numbers of List in RecyclerView.
    private static final int LENGTH = 18;

    public ContentAdapter() {
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(parent.getContext()), parent);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        // no-op
    }

    @Override
    public int getItemCount() {
        return LENGTH;
    }
}

fragment_recipes

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="?android:attr/selectableItemBackground"
android:orientation="vertical"
android:padding="@dimen/tile_padding">



<ImageView
    android:layout_width="match_parent"
    android:layout_height="@dimen/tile_height"
    android:scaleType="centerCrop"
    android:src="@drawable/paris" />


<ImageView
    android:layout_width="match_parent"
    android:layout_height="@dimen/tile_height"
    android:alpha="0.3"
    android:background="@color/dark_grey" />

<TextView
    android:id="@+id/tile_title"
    android:layout_width="match_parent"
    android:layout_height="@dimen/tile_height"
    android:layout_gravity="center"
    android:gravity="center"
    android:text="@string/item_title"
    android:textColor="@color/white"
    android:textSize="@dimen/article_titles" />

Main_Activity

  static class Adapter extends FragmentPagerAdapter {
    private final List<Fragment> mFragmentList = new ArrayList<>() ;
    private final List<String> mFragmentTitleList = new ArrayList<>();

    public Adapter(FragmentManager manager) {
        super(manager);
    }

0 个答案:

没有答案
相关问题