我必须在带有点作为指示符的回收站视图中制作滚动图像。请查看相同的附加屏幕截图。圆圈图像是点指示符。
到目前为止,我已经使用了RecyclerView并使用了GridLayoutManager。在内部适配器我已经制作了另一个项目HEADER_TYPE,即用于滚动图像。对于滚动我正在使用this库并已成功导入到我的项目中。
由于我是android的新手,我无法进一步移动,我不知道如何在我的项目中使用它。
另外请建议它是否是正确的路径,以达到相同的结果或建议另一种方式做同样的事情。
到目前为止我的代码:
public static final int TYPE_HEADER = 1;
public static final int TYPE_ITEM = 0;
List<CatetoryListModel> data = Collections.emptyList();
LayoutInflater inflater;
Context context;
public CategoryRecyclerAdapter(Context context, List<CatetoryListModel> data) {
inflater = LayoutInflater.from(context);
this.data = data;
this.context = context;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType == TYPE_HEADER) {
View view = inflater.inflate(R.layout.recycler_header, parent, false);
MyViewHolderHeader myViewHolder = new MyViewHolderHeader(view, context);
return myViewHolder;
} else {
View view = inflater.inflate(R.layout.recycler_custom_row, parent, false);
MyViewHolder myViewHolder = new MyViewHolder(view, context);
return myViewHolder;
}
}
@Override
// public void onBindViewHolder(MyViewHolder holder, int position) {
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
// StaggeredGridLayoutManager.LayoutParams layoutParams = (StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams();
// layoutParams.setFullSpan(true);
if (holder instanceof MyViewHolder) {
CatetoryListModel current = data.get(position - 1); //potion now becomes 1 and data start from 0 index
//holder.title.setText(current.getCategoryName());
// holder.desp.setText(current.getDescription());
((MyViewHolder) holder).icon.setImageResource(current.getImgSrc());
} else {
// ((MyViewHolderHeader) holder).icon.setImageResource(R.drawable.banner);
}
}
@Override
public int getItemViewType(int position) {
if (position == 0)
return TYPE_HEADER;
return TYPE_ITEM;
}
//Returns the total number of items in the data set hold by the adapter.
//no of items to be rendered by adapter
@Override
public int getItemCount() {
return data.size() + 1;
}
class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView title;
TextView desp;
ImageView icon;
Context cntxt;
public MyViewHolder(View itemView, Context c) {
super(itemView);
cntxt = c;
itemView.setClickable(true);
itemView.setOnClickListener(this);
// title = (TextView)itemView.findViewById(R.id.category);
// desp = (TextView)itemView.findViewById(R.id.description);
icon = (ImageView) itemView.findViewById(R.id.imgsrc);
}
@Override
public void onClick(View v) {
Toast.makeText(cntxt, "Hello", Toast.LENGTH_LONG).show();
}
}
class MyViewHolderHeader extends RecyclerView.ViewHolder {
//ImageView icon;
// ViewPager mPager;
// CirclePageIndicator mIndicator;
// TestFragmentAdapter mAdapter;
public MyViewHolderHeader(View itemView, Context c) {
super(itemView);
// mAdapter = new TestFragmentAdapter(getSupportFragmentManager());
// mPager = (ViewPager)itemView.findViewById(R.id.pager);
// mPager.setAdapter(mAdapter);
// mIndicator = (CirclePageIndicator)itemView.findViewById(R.id.indicator);
// mIndicator.setViewPager(mPager);
}
}
recycler_header.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<com.viewpagerindicator.CirclePageIndicator
android:id="@+id/indicator"
android:padding="10dip"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
/>
recycler_custom_row.xml
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
card_view:cardCornerRadius="4dp"
android:id="@+id/card_view"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/imgsrc"
android:src="@drawable/close" />
</RelativeLayout>