Recycler view cardview showing wrap parent instead of match parent - android

I have passed the parent to onCreateViewHolder instead of null but it is not showing match parent.
Please tell me if there is any error in the code?
Here is my Main_Adapter.class:
public class Main_Adapter extends RecyclerView.Adapter<Main_Adapter.ViewHolder> {
private List<MainModel> mainModels;
private Context context;
private OnClicklisteners listener;
public Main_Adapter(List<MainModel> mainModels, Context context, OnClicklisteners onClicklisteners) {
this.mainModels = mainModels;
this.context = context;
this.listener=onClicklisteners;
}
public interface OnClicklisteners{
public void onPosClicked(View view, int pos, ImageView mainimage, ArrayList<Integer> colorlist);
}
#Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.main_card, parent, false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(final ViewHolder holder, int position) {
holder.main_text.setText(mainModels.get(position).getName());
Picasso.with(context).load(mainModels.get(position).getImageName()).fit().centerInside().into(holder.mainimage);
}
#Override
public int getItemCount() {
return mainModels.size();
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
#BindView(R.id.main_image)
ImageView mainimage;
#BindView(R.id.main_text)
TextView main_text;
Typeface ubuntu;
int colors;
ArrayList<Integer> colorlist =new ArrayList<>();
public ViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
itemView.setOnClickListener(this);
}
#Override
public void onClick(View view) {
int pos = getAdapterPosition();
listener.onPosClicked(view,pos,mainimage,colorlist);
}
}
Here is main_card.xml:
<android.support.v7.widget.CardView android:id="#+id/movie_container"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_gravity="center"
android:clickable="true"
android:layout_margin="2dp"
android:foreground="?attr/selectableItemBackground"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="2dp"
xmlns:card_view="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<ImageView
android:layout_marginTop="50dp"
android:id="#+id/main_image"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_gravity="center"
android:background="#color/white"
android:scaleType="centerCrop"
/>
<TextView
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/main_text"
android:textSize="16sp"
android:text="hello"
android:textAlignment="center"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
Here is a screenshot:
It should show full width but it's showing only a wrap content. I have found a similar post but they are telling to pass parent in onCreateViewHolder. I have done that but it didn't help me.

Related

NavigationAdapter Using Two Icons

I use navigationview. I want to use two icons in navigation view. Currently, when I use .seticon, it changes 2 icons. I want to define icons in two icons separately. I want to define separate icons for navIconNew and navIcon. How can we do that?
Navigation Adapter
public class NavigationAdapter extends RecyclerView.Adapter<NavigationAdapter.ViewHolder> {
Context context;
ArrayList<NavigationDataModel> arrayList = new ArrayList<>();
public NavigationAdapter(Context context, ArrayList<NavigationDataModel> arrayList) {
this.context = context;
this.arrayList = arrayList;
}
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.navigationrecyclerview_adapter11, parent, false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
holder.navIcon.setImageResource(arrayList.get(position).getIcon());
holder.navIconNew.setImageResource(arrayList.get(position).getIcon());
holder.rootView.setBackgroundColor(arrayList.get(position).getColor());
holder.navTitle.setText(arrayList.get(position).getTitle());
}
#Override
public int getItemCount() {
return arrayList.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
ImageView navIcon, navIconNew;
TextView navTitle;
LinearLayout rootView;
public ViewHolder(View itemView) {
super(itemView);
rootView = itemView.findViewById(R.id.rootView);
navIcon = itemView.findViewById(R.id.navIcon);
navIconNew = itemView.findViewById(R.id.navIconNew);
navTitle = itemView.findViewById(R.id.navTitle);
}
}
navigationrecyclerview_adapter11
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="#+id/rootView"
android:orientation="horizontal"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/navIcon"
android:layout_margin="10dp"
android:layout_marginTop="10dp"
android:layout_alignParentLeft="true"
android:tint="#color/white"
android:layout_width="30dp"
android:layout_height="30dp"
/>
<ImageView
android:id="#+id/navIconNew"
android:layout_margin="10dp"
android:layout_marginTop="10dp"
android:layout_alignParentLeft="true"
android:tint="#color/white"
android:layout_width="30dp"
android:layout_height="30dp"
/>
<TextView
android:id="#+id/navTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lineSpacingMultiplier="0.6"
android:text="Item"
android:fontFamily="#font/sanspro_semibold"
android:textColor="#color/white"
android:textSize="20dp"
android:layout_marginTop="10dp"
/>
</LinearLayout>
Activity
NavigationDataModel model8 = new NavigationDataModel();
model8.setColor(ContextCompat.getColor(this, R.color.red));
model8.setTitle("Mesaj At");
model8.setIcon(R.drawable.unread);
arrayList.add(model8);

How to prevent ScrollView move up when selecting the last item of RecyclerView?

I design a layout and I get a problem with ScrollView. Specially, I have a ScrollView and a RecyclerView inside this ScrollView. When I select items in the last row of RecyclerView, the View does not stay at the last row, it moves up to the upper row.
For example, my view has 4 rows. When I select an item in 4th row, the view automatically moves up to 3th row. So, how I can prevent it so that when I select items in the last row, the view will stay and not move up? Thank you
Layout:
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/selectPayment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:text="#string/select_payment_method"
android:textSize="#dimen/sp_20"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/choosePayment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:textSize="#dimen/sp_16"
android:text="#string/choose_payment_method"
app:layout_constraintStart_toStartOf="#+id/selectPayment"
app:layout_constraintTop_toBottomOf="#+id/selectPayment" />
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="#dimen/dp_30"
android:layout_marginBottom="10dp"
android:fadeScrollbars="false"
app:layout_constraintBottom_toTopOf="#+id/continueButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/choosePayment">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/paymentMethodRV"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</ScrollView>
<Button
android:id="#+id/continueButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/continue_in_cap"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Adapter:
public class PaymentAdapter extends RecyclerView.Adapter<PaymentAdapter.ViewHolder> {
private Context context;
private List<CardItems> cardItemsList;
private int rowIndex = -1;
public PaymentAdapter(Context context, List<CardItems> cardItemsList) {
this.context = context;
this.cardItemsList = cardItemsList;
}
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.payment_method_items, parent, false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
holder.paymentImage.setImageResource(cardItemsList.get(position).getCardImage());
holder.paymentTitle.setText(cardItemsList.get(position).getCardNumber());
holder.setItemClickListener(new ItemClickListener() {
#Override
public void onItemClick(int position) {
rowIndex = position;
notifyDataSetChanged();
}
});
//set highlight color when option is clicked
if (rowIndex == position){
holder.frameContainer.setBackgroundResource(R.drawable.green_rounded_button);
}
else {
holder.frameContainer.setBackgroundResource(R.drawable.white_grey_rounded_button);
}
}
#Override
public int getItemCount() {
return cardItemsList.size();
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
ImageView paymentImage;
TextView paymentTitle;
FrameLayout frameContainer;
ItemClickListener itemClickListener;
public ViewHolder(#NonNull View itemView) {
super(itemView);
paymentImage = itemView.findViewById(R.id.paymentImage);
paymentTitle = itemView.findViewById(R.id.paymentTitle);
frameContainer = itemView.findViewById(R.id.frameContainer);
itemView.setOnClickListener(this);
}
//handle click on each category
#Override
public void onClick(View view) {
itemClickListener.onItemClick(getAdapterPosition());
notifyDataSetChanged();
}
public void setItemClickListener(ItemClickListener listener){
itemClickListener = listener;
}
}
//for listening from holder
public interface ItemClickListener{
void onItemClick(int position);
}
}

Using vector images in RecycleView

RecyclerView Adapter Class.
public class TravelListAdapter extends RecyclerView.Adapter<TravelListAdapter.ViewHolder> {
Context mContext;
OnItemClickListener mItemClickListener;
String []names = {"Hotels", "Travel", "Medicine", "Education", "Travel", "Hotels"};
private int[] advertImageList = {R.drawable.hotel, R.drawable.travel, R.drawable.medical, R.drawable.education, R.drawable.travel, R.drawable.hotel};
// 2
public void setOnItemClickListener(OnItemClickListener mItemClickListener) {
this.mItemClickListener = mItemClickListener;
}
public TravelListAdapter(Context context) {
this.mContext = context;
}
// 3
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
public LinearLayout placeHolder;
public LinearLayout placeNameHolder;
public TextView placeName;
public ImageView placeImage;
public ViewHolder(View itemView) {
super(itemView);
placeHolder = itemView.findViewById(R.id.mainHolder);
placeName = itemView.findViewById(R.id.placeName);
placeNameHolder = itemView.findViewById(R.id.placeNameHolder);
placeImage = itemView.findViewById(R.id.placeImage);
placeHolder.setOnClickListener(this);
}
#Override
public void onClick(View v) {
if (mItemClickListener != null) {
mItemClickListener.onItemClick(itemView, getPosition());
}
}
}
public interface OnItemClickListener {
void onItemClick(View view, int position);
}
#Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.category_row_item, parent, false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(final ViewHolder holder, int position) {
// final Place place = new PlaceData().placeList().get(position);
holder.placeName.setText(names[position]);
holder.placeName.setTextColor(R.color.black);
Picasso.with(mContext).load(advertImageList[position]).into(holder.placeImage);
Bitmap photo = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.image2);
Palette.generateAsync(photo, new Palette.PaletteAsyncListener() {
public void onGenerated(Palette palette) {
//int bgColor = palette.getMutedColor(mContext.getResources().getColor(android.R.color.transparent));
holder.placeNameHolder.setBackgroundColor(mContext.getResources().getColor(android.R.color.transparent));
}
});
}
#Override
public int getItemCount() {
return names.length;
}
}`
My Xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/placeCard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:cardBackgroundColor="#android:color/transparent">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<android.support.v7.widget.AppCompatImageView
android:id="#+id/placeImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="center"
android:transitionName="tImage"
android:layout_centerInParent="true"
android:tint="#android:color/white"
android:padding="10dp"/>
<!-- Used for the ripple effect on touch -->
<LinearLayout
android:id="#+id/mainHolder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?android:selectableItemBackground"
android:orientation="horizontal" />
<LinearLayout
android:id="#+id/placeNameHolder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal"
android:transitionName="tNameHolder"
android:padding="5dp"
android:layout_below="#+id/placeImage">
<TextView
android:id="#+id/placeName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceListItem"
android:textColor="#android:color/white"/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
I am using vector images generated from Android Studio but those images are not displayed in recyclerView.
What should i do? Let me mention that the vector images that i use inside recyclerView are properly displayed if i use them in simple image views.

RecyclerView onClick not working properly?

I am using RecyclerView in my fragment to show images with text in Grid format,the Recycler view grid_item.xml look like following:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="#id/card_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_margin="#dimen/card_margin_grid"
card_view:cardCornerRadius="#dimen/card_album_radius">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="#id/thumbnail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="?selectableItemBackgroundBorderless"
android:clickable="true"
android:scaleType="fitCenter" />
<TextView
android:id="#id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/thumbnail"
android:layout_margin="#dimen/album_title_padding"
android:textColor="#color/album_title"
android:textSize="#dimen/album_title" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
I am using adapter to populate data in RecyclerView, the code for this is :
public class DataAdapter extends RecyclerView.Adapter<DataAdapter.ViewHolder> {
private ArrayList<Movie> movies;
private Context context;
public DataAdapter(Context context, ArrayList<Movie> movies) {
this.movies = movies;
this.context = context;
}
public void addItems(ArrayList<Movie> movies) {
this.movies.addAll(movies);
}
#Override
public DataAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.recycler_view_grid_item, viewGroup, false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(DataAdapter.ViewHolder viewHolder, int i) {
viewHolder.title.setText(movies.get(i).getTitle());
Picasso.with(context).load(movies.get(i).getImage_url_medium()).placeholder(R.drawable.placeholder).into(viewHolder.thumbnail);
}
#Override
public int getItemCount() {
return movies.size();
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private TextView title;
private ImageView thumbnail;
public ViewHolder(View view) {
super(view);
title = (TextView) view.findViewById(R.id.title);
thumbnail = (ImageView) view.findViewById(R.id.thumbnail);
view.setOnClickListener(this);
}
// Handles the row being being clicked
#Override
public void onClick(View view) {
int position = getAdapterPosition(); // gets item position
if (position != RecyclerView.NO_POSITION) { // Check if an item was deleted, but the user clicked it before the UI removed it
Movie movie = movies.get(position);
// start detail activity
Intent i = new Intent(context, MovieDetail.class);
i.putExtra(Constants.MOVIES_OBJECT, movie);
context.startActivity(i);
}
}
}
}
My problem is click listener is only working on the TextView and not on the image , although I have set click listener on whole view which contains both image and text.Is something wrong with my implementation ?
try setting android:focusableInTouchMode="false" to your imageview.
and remove android:clickable="true" or set it to false
Use viewHolder.itemView like :
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//your action
});
This will enable click action on whole RecyclerView item.
Add android:clickable="true" to the root RelativeLayout.
<?xml version="1.0" encoding="utf-8"?>
<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:id="#id/card_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_margin="#dimen/card_margin_grid"
android:clickable="true"
android:focusableInTouchMode="true"
card_view:cardCornerRadius="#dimen/card_album_radius">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="#id/thumbnail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="?selectableItemBackgroundBorderless"
android:clickable="false"
android:focusableInTouchMode="false"
android:scaleType="fitCenter" />
<TextView
android:id="#id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/thumbnail"
android:layout_margin="#dimen/album_title_padding"
android:textColor="#color/album_title"
android:textSize="#dimen/album_title" />
</RelativeLayout>
</android.support.v7.widget.CardView>
public class OffersRecycleViewAdapter extends RecyclerView.Adapter {
private Activity mActivity;
private List<OfferShopModel> offerShopModels = new ArrayList<>();
ArrayList<String> allColors = new ArrayList<String>();
public OffersRecycleViewAdapter(List<OfferShopModel> offerShopModels, Activity activity, ArrayList<String> allColors) {
this.offerShopModels = offerShopModels;
this.mActivity = activity;
}
// String[] allColors = mActivity.getResources().getStringArray(R.array.colors);
#Override
public ItemViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.cardview_offers, viewGroup, false);
return new ItemViewHolder(v);
}
#TargetApi(Build.VERSION_CODES.M)
#Override
public void onBindViewHolder(ItemViewHolder itemViewHolder, final int position) {
itemViewHolder.mOffer.setText(offerShopModels.get(position).getOffer());
}
#Override
public int getItemCount() {
return offerShopModels.size();
}
class ItemViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
ImageView mLinearLayoutBack;
TextView mOffer;
ItemViewHolder(View itemView) {
super(itemView);
mOffer = (TextView) itemView.findViewById(R.id.offer);
mOffer.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// call click event
}
}
}
remove android:clickable="true" from your ImageView or change it to android:clickable="false"

The distance between card view is too large

I am using cardview with recycler view.But earlier I used the same code to do things without any problems.But now I am using fragments. Now I am getting the distance between the cardviews are greater.
my recycler view adapter
public static class DataObjectHolder extends RecyclerView.ViewHolder implements View.OnClickListener
{
TextView label;
TextView dateTime;
ImageView imageView;
ProgressBar progressBar;
public DataObjectHolder(final View itemView, final Context activity, final ArrayList<DataObject> myDataset) {
super(itemView);
label = (TextView) itemView.findViewById(R.id.textView);
//dateTime = (TextView) itemView.findViewById(R.id.thot);
imageView=(ImageView)itemView.findViewById(R.id.iproductimg);
progressBar=(ProgressBar)itemView.findViewById(R.id.progress);
Log.i(LOG_TAG, "Adding Listener");
itemView.setOnClickListener(this);
}
#Override
public void onClick(View v) {
myClickListenerhi.onItemClick(getLayoutPosition(),v);
}
}
public MyRecyclerViewAdapter(Activity context, ArrayList<DataObject> myDataset,MyClickListener myClickListener1) {
mDataset = myDataset;
activityContext=context;
myClickListenerhi=myClickListener1;
}
#Override
public DataObjectHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.cardview, parent, false);
DataObjectHolder dataObjectHolder = new DataObjectHolder(view,activityContext,mDataset);
return dataObjectHolder;
}
#Override
public void onBindViewHolder(final DataObjectHolder holder, int position) {
Context context=null;
holder.label.setText(mDataset.get(position).getmText1());
// holder.dateTime.setText(mDataset.get(position).getmText2());
Drawable placeholder = holder.imageView.getContext().getResources().getDrawable(R.drawable.placeholder);
holder.imageView.setImageDrawable(placeholder);
//new ImageDownloaderTask(holder.imageView).execute(mDataset.get(position).getUrl());
mDataset.get(position).setPosition(position);
Picasso.with(activityContext)
.load(mDataset.get(position).getUrl())
.placeholder(R.drawable.placeholder)
.into(holder.imageView, new Callback() {
#Override
public void onSuccess() {
holder.progressBar.setVisibility(View.INVISIBLE);
}
#Override
public void onError() {
}
});
}
public void addItem(DataObject dataObj, int index) {
mDataset.add(index, dataObj);
notifyItemInserted(index);
}
public void deleteItem(int index) {
mDataset.remove(index);
notifyItemRemoved(index);
}
#Override
public int getItemCount() {
return mDataset.size();
}
public interface MyClickListener {
void onItemClick(int position, View v);
}
}
my cardview
<LinearLayout 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"
android:weightSum="3"
>
<android.support.v7.widget.CardView
android:id="#+id/card_view"
android:layout_width="156dp"
android:layout_height="242dp"
android:layout_margin="5dp"
card_view:cardCornerRadius="2dp"
card_view:contentPadding="5dp"
card_view:cardBackgroundColor="#ffffff">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="200dp"
android:id="#+id/iproductimg"
android:src="#drawable/placeholder"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:scaleType="fitXY" />
<ProgressBar
android:id="#+id/progress"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="visible"
android:indeterminate="false" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:id="#+id/firstheadtxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_below="#+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
The error
I solved this by changing Cardview LinearLayout attribute from
android:layout_width="match_parent"
android:layout_height="match_parent"
to
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Edit:
Main problem is that the recyclerviews child layout or item layout rootview attribute is match_parent.
change it attribut to wrap_content
android:layout_width="wrap_content"
android:layout_height="wrap_content"
In this case : in the layout of cardview:
remove :layout_margin="5dp"
add :
margin_top = "3dp"
margin_left = "5dp"
margin_right = "5dp"

Categories

Resources