gpt4 book ai didi

android - 如何阻止 RecyclerView 在主行下方显示空行?

转载 作者:行者123 更新时间:2023-11-29 01:25:36 25 4
gpt4 key购买 nike

我在我的应用程序中使用了 Recycler view 和 Card View。

当我为 Imageview 设置一些高度时,它会在 Recycler View 下方显示空行。

如何删除空行?

我在下面的截图中强调了这个问题。

请在下面找到代码。

项目 View .xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
card_view:cardCornerRadius="5dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<ImageView
android:id="@+id/img_row_women"
android:layout_width="190dp"
android:layout_height="150dp"
android:layout_margin="7dp"
android:scaleType="fitXY" />


<TextView
android:id="@+id/txv_women_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:text="" />

<TextView
android:id="@+id/txv_women_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:text="" />

</LinearLayout>


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

<android.support.v7.widget.CardView

android:layout_width="match_parent"
android:layout_height="275dp"
android:layout_margin="5dp"
card_view:cardCornerRadius="5dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<ImageView
android:id="@+id/img_row_men"
android:layout_width="190dp"
android:layout_height="150dp"
android:layout_margin="7dp"
android:scaleType="fitXY" />


<TextView
android:id="@+id/txv_men_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:text="" />

<TextView
android:id="@+id/txv_men_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:text="" />


</LinearLayout>


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

主.xml

<?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"

android:orientation="vertical"
android:weightSum="2">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="15dp"
android:layout_weight="1"
android:orientation="horizontal">


<TextView

android:id="@+id/tab1_women"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Womens"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000"
android:textSize="20dp"

/>

<TextView
android:id="@+id/tab1_women_viewall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="View all"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000"
android:textSize="20dp" />

<android.support.v7.widget.RecyclerView
android:id="@+id/recycleView_women"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="30dp"
android:clipToPadding="false"
android:minHeight="250dp">

</android.support.v7.widget.RecyclerView>

</RelativeLayout>

<RelativeLayout

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="15dp"
android:orientation="horizontal">


<TextView

android:id="@+id/tab1_men"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mens"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000"
android:textSize="20dp"

/>

<TextView
android:id="@+id/tab1_men_viewall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="View all"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000"
android:textSize="20dp" />

<android.support.v7.widget.RecyclerView
android:id="@+id/recycleView_men"

android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="30dp"
android:minHeight="250dp">

</android.support.v7.widget.RecyclerView>

</RelativeLayout>


</LinearLayout>

我的适配器.java

public class MyCustomAdapter_Cardview extends RecyclerView.Adapter<MyCustomAdapter_Cardview.MyViewHolder> {


Context context;

ArrayList<RowItem> val;
RowItem ri = new RowItem();

LayoutInflater inflater;


public MyCustomAdapter_Cardview(Context context, ArrayList<RowItem> val) {

this.context = context;
this.val = val;
inflater = LayoutInflater.from(context);

}

@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int position) {

View view = inflater.inflate(R.layout.list_item_row, parent, false);

MyViewHolder holder = new MyViewHolder(view);

return holder;
}

@Override
public void onBindViewHolder(MyViewHolder myViewHolder, final int position) {

ri = val.get(position);
myViewHolder.textview_women_name.setText(ri.getTitle());
Picasso.with(context).load("" + ri.getImage()).into(myViewHolder.imageView_women);



}


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


class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

TextView textview_women_name, textView_men, textView_des_women, textView_des_men;
ImageView imageView_women, imageView_men;


public MyViewHolder(View itemView) {
super(itemView);

textview_women_name = (TextView) itemView.findViewById(R.id.txv_women_name);
imageView_women = (ImageView) itemView.findViewById(R.id.img_row_women);
textView_des_women = (TextView) itemView.findViewById(R.id.txv_women_description);

textView_men = (TextView) itemView.findViewById(R.id.txv_men_name);
imageView_men = (ImageView) itemView.findViewById(R.id.img_row_men);
textView_des_men = (TextView) itemView.findViewById(R.id.txv_men_description);


}

@Override
public void onClick(View view) {
/* Intent intent = new Intent(view.getContext(), Tab1.class);
SharedPreferences sharedPreferences = context.getSharedPreferences("Fashion", Context.MODE_PRIVATE);

SharedPreferences.Editor sedt = sharedPreferences.edit();
sedt.putString("textvalue", textView_des_women.getText().toString());
sedt.putString("txtopertaive", textview_women_name.getText().toString());
sedt.commit();
view.getContext().startActivity(intent);*/

}

}


}

enter image description here

最佳答案

好的....在你的适配器里面放这段代码....

@Override
public void onBindViewHolder(MyViewHolder myViewHolder, final int position) {

myViewHolder.raw2.setVisibility(View.Gone);
ri = val.get(position);
myViewHolder.textview_women_name.setText(ri.getTitle());
Picasso.with(context).load("" + ri.getImage()).into(myViewHolder.imageView_women);
}

class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

CardView raw1,raw2;
TextView textview_women_name, textView_men, textView_des_women, textView_des_men;
ImageView imageView_women, imageView_men;


public MyViewHolder(View itemView) {
super(itemView);

textview_women_name = (TextView) itemView.findViewById(R.id.txv_women_name);
imageView_women = (ImageView) itemView.findViewById(R.id.img_row_women);
textView_des_women = (TextView) itemView.findViewById(R.id.txv_women_description);

textView_men = (TextView) itemView.findViewById(R.id.txv_men_name);
imageView_men = (ImageView) itemView.findViewById(R.id.img_row_men);
textView_des_men = (TextView) itemView.findViewById(R.id.txv_men_description);

raw1 = (CardView) itemview.findViewById(R.id.raw1);
raw2 = (CardView) itemview.findViewById(R.id.raw2);

}

关于android - 如何阻止 RecyclerView 在主行下方显示空行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34287598/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com