Android RecyclerView在滚动时更改高度如何解决此问题?

Android RecyclerView在滚动时更改高度如何解决此问题?,android,android-recyclerview,android-glide,Android,Android Recyclerview,Android Glide,我正在使用recyclerview来显示一些产品的照片,当我打开应用程序时,效果非常好,但当我滚动时,每张卡的高度会变大,然后当我打开键盘时,高度会变大,然后当我滚动时,它又变大了,我不知道如何修复 xml 适配器 public class ProductsAdapter extends RecyclerView.Adapter<ProductsAdapter.ViewHolder>{ private Context mContext; private List<Pro

我正在使用recyclerview来显示一些产品的照片,当我打开应用程序时,效果非常好,但当我滚动时,每张卡的高度会变大,然后当我打开键盘时,高度会变大,然后当我滚动时,它又变大了,我不知道如何修复

xml


适配器

public  class ProductsAdapter extends RecyclerView.Adapter<ProductsAdapter.ViewHolder>{

private Context mContext;
private List<Product> productList;

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View itemView = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.product_card, parent, false);

    return new ProductsAdapter.ViewHolder(itemView);

}

@Override
public void onBindViewHolder(final ViewHolder holder, int position) {

    Product album = productList.get(position);
    holder.title.setText(album.getName());
    holder.price.setText(album.getPrice() + " DZA");

    // loading album cover using Glide library
    Glide.with(mContext).load(album.getThumbnail()).into(holder.thumbnail);

    holder.overflow.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            showPopupMenu(holder.overflow);
        }
    });
}

@Override
public int getItemCount() {
    return productList.size();
}

public class ViewHolder extends RecyclerView.ViewHolder{
    public TextView title, price;
    public ImageView thumbnail, overflow;

    public ViewHolder (View itemView){
        super (itemView);
        title = (TextView) itemView.findViewById(R.id.title);
        price = (TextView) itemView.findViewById(R.id.count);
        thumbnail = (ImageView) itemView.findViewById(R.id.thumbnail);
        overflow = (ImageView) itemView.findViewById(R.id.overflow);
    }
}

public ProductsAdapter(Context mContext, List<Product> productList) {
    this.mContext = mContext;
    this.productList = productList;
}
private void showPopupMenu(View view) {
    // inflate menu
    PopupMenu popup = new PopupMenu(mContext, view);
    MenuInflater inflater = popup.getMenuInflater();
    inflater.inflate(R.menu.menu_product_card, popup.getMenu());
    popup.setOnMenuItemClickListener(new MyMenuItemClickListener());
    popup.show();
}
class MyMenuItemClickListener implements PopupMenu.OnMenuItemClickListener {

    public MyMenuItemClickListener() {
    }

    @Override
    public boolean onMenuItemClick(MenuItem menuItem) {
        switch (menuItem.getItemId()) {
            case R.id.action_add_favourite:
                Toast.makeText(mContext, "Add to favourite", Toast.LENGTH_SHORT).show();
                return true;
            case R.id.action_play_next:
                Toast.makeText(mContext, "Play next", Toast.LENGTH_SHORT).show();
                return true;
            default:
        }
        return false;
    }
}
}
公共类ProductsAdapter扩展了RecyclerView.Adapter{
私有上下文;
私有列表产品列表;
@凌驾
public ViewHolder onCreateViewHolder(视图组父级,int-viewType){
View itemView=LayoutInflater.from(parent.getContext())
.充气(R.layout.product_卡,父级,假);
返回新产品Adapter.ViewHolder(itemView);
}
@凌驾
公共无效onBindViewHolder(最终ViewHolder,内部位置){
Product album=productList.get(位置);
holder.title.setText(album.getName());
holder.price.setText(album.getPrice()+“DZA”);
//使用Glide库加载相册封面
Glide.with(mContext).load(album.getThumbnail())到(holder.thumbnail)中;
holder.overflow.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
showPopupMenu(holder.overflow);
}
});
}
@凌驾
public int getItemCount(){
返回productList.size();
}
公共类ViewHolder扩展了RecyclerView.ViewHolder{
公共文本视图标题、价格;
公共图像视图缩略图,溢出;
公共视图持有者(视图项视图){
超级(项目视图);
title=(TextView)itemView.findViewById(R.id.title);
price=(TextView)itemView.findViewById(R.id.count);
缩略图=(ImageView)itemView.findViewById(R.id.缩略图);
溢出=(ImageView)itemView.findViewById(R.id.overflow);
}
}
公共产品适配器(上下文mContext,列表productList){
this.mContext=mContext;
this.productList=productList;
}
私有void显示弹出菜单(视图){
//充气菜单
PopupMenu popup=新的PopupMenu(mContext,视图);
MenuInflater充气器=弹出窗口。getMenuInflater();
充气器。充气(R.menu.menu_产品_卡,popup.getMenu());
setOnMenuItemClickListener(新的MyMenuItemClickListener());
popup.show();
}
类MyMenuItemClickListener实现PopupMenu.OnMenuItemClickListener{
公共MyMenuItemClickListener(){
}
@凌驾
公共布尔onMenuItemClick(MenuItem MenuItem){
开关(menuItem.getItemId()){
案例R.id.action\u add\u Favorite:
Toast.makeText(mContext,“添加到收藏夹”,Toast.LENGTH_SHORT.show();
返回true;
案例R.id.行动\游戏\下一步:
Toast.makeText(mContext,“下一步播放”,Toast.LENGTH_SHORT.show();
返回true;
违约:
}
返回false;
}
}
}
product_card.xml `

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.v7.widget.CardView
        android:id="@+id/card_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_margin="@dimen/card_margin"
        android:elevation="3dp"
        card_view:cardMaxElevation="8dp"
        card_view:cardCornerRadius="@dimen/card_album_radius">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:id="@+id/thumbnail"
                android:layout_width="match_parent"
                android:layout_height="@dimen/album_cover_height"
                android:background="?attr/selectableItemBackgroundBorderless"
                android:clickable="true"
                android:scaleType="fitXY" />

            <TextView
                android:id="@+id/title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/thumbnail"
                android:paddingLeft="@dimen/album_title_padding"
                android:paddingRight="@dimen/album_title_padding"
                android:paddingTop="@dimen/album_title_padding"
                android:textColor="@color/album_title"
                android:textSize="@dimen/album_title" />

            <TextView
                android:id="@+id/count"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/title"
                android:paddingBottom="@dimen/songs_count_padding_bottom"
                android:paddingLeft="@dimen/album_title_padding"
                android:paddingRight="@dimen/album_title_padding"
                android:textSize="@dimen/songs_count" />

            <ImageView
                android:id="@+id/overflow"
                android:layout_width="@dimen/ic_album_overflow_width"
                android:layout_height="@dimen/ic_album_overflow_height"
                android:layout_alignParentRight="true"
                android:layout_below="@id/thumbnail"
                android:layout_marginTop="@dimen/ic_album_overflow_margin_top"
               android:scaleType="centerCrop"
                android:src="@drawable/ic_dots" />

        </RelativeLayout>

    </android.support.v7.widget.CardView>
</LinearLayout>

我解决了这个问题,这都是关于包装内容和匹配家长的问题。我犯了一个非常愚蠢的错误,对不起大家。 我将match_parent更改为在cardview中包装内容,现在效果非常好。
谢谢大家。

向你们展示适配器编码你们可以用(mContext)Glide.with(mContext.load(album.getThumbnail()).into(holder.thumbnail)发表评论;线路和测试。只是为了确保Glide没有问题,而且如果您
post-product\u-card.xml
我刚刚尝试过它,效果会更好,总是一样的problem@Raghunandan我刚刚发布了product_card.xml,您是否发现任何错误或其他东西。。?
 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.v7.widget.CardView
        android:id="@+id/card_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_margin="@dimen/card_margin"
        android:elevation="3dp"
        card_view:cardMaxElevation="8dp"
        card_view:cardCornerRadius="@dimen/card_album_radius">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:id="@+id/thumbnail"
                android:layout_width="match_parent"
                android:layout_height="@dimen/album_cover_height"
                android:background="?attr/selectableItemBackgroundBorderless"
                android:clickable="true"
                android:scaleType="fitXY" />

            <TextView
                android:id="@+id/title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/thumbnail"
                android:paddingLeft="@dimen/album_title_padding"
                android:paddingRight="@dimen/album_title_padding"
                android:paddingTop="@dimen/album_title_padding"
                android:textColor="@color/album_title"
                android:textSize="@dimen/album_title" />

            <TextView
                android:id="@+id/count"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/title"
                android:paddingBottom="@dimen/songs_count_padding_bottom"
                android:paddingLeft="@dimen/album_title_padding"
                android:paddingRight="@dimen/album_title_padding"
                android:textSize="@dimen/songs_count" />

            <ImageView
                android:id="@+id/overflow"
                android:layout_width="@dimen/ic_album_overflow_width"
                android:layout_height="@dimen/ic_album_overflow_height"
                android:layout_alignParentRight="true"
                android:layout_below="@id/thumbnail"
                android:layout_marginTop="@dimen/ic_album_overflow_margin_top"
               android:scaleType="centerCrop"
                android:src="@drawable/ic_dots" />

        </RelativeLayout>

    </android.support.v7.widget.CardView>
</LinearLayout>