1.i는 일부 recyclerviews를 구현했으며 일부 항목에는 여분의 빈 공간이 있습니다. 이 공간은 때로는 일부 스크롤 후에 사라집니다. 나는 네가 생각할 수있는 모든 방법을 시험해 보았다! 나는 콘텐츠를 감싸기 위해 높이를 변경했지만 여전히 문제가 있습니다! 항목 XML 여기 Recyclerview empty spaceRecyclerView 항목 사이에 여분의 공백이 있음
됩니다 :
<android.support.v7.widget.CardView
android:id="@+id/btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:gravity="center"
android:orientation="horizontal"
android:adjustViewBounds="true"
android:padding="8dp"
android:layout_margin="6dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/banner_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/no_image_banner" />
<TextView
android:id="@+id/txtHey"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:gravity="center"
android:maxLength="20"
android:text="sadas"
android:textColor="#4d4a46"
android:textSize="11dp"
android:textStyle="bold" />
<TextView
android:id="@+id/txtHi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:gravity="center"
android:text="sadas"
android:textColor="#999999"
android:textSize="9dp" />
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_vertical">
<TextView
android:id="@+id/txtPrice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="sadas"
android:textColor="#888888"
android:textSize="9dp" />
<LinearLayout
android:id="@+id/price_cancel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:background="#888888"
android:orientation="horizontal" />
</FrameLayout>
<TextView
android:id="@+id/txtFinalPrice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="sadas"
android:textColor="#3dc24d"
android:textSize="9dp" />
<TextView
android:id="@+id/txtHello"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="hey"
android:textSize="9dp"
android:visibility="gone" />
</LinearLayout>
</android.support.v7.widget.CardView>
메인 페이지의 XML :
<android.support.design.widget.AppBarLayout
android:id="@+id/topBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<include
layout="@layout/toolbar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/product_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="6dp"
>
</android.support.v7.widget.RecyclerView>
<TextView
android:id="@+id/request_results"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textSize="21dp"
android:textStyle="bold" />
</RelativeLayout>
여기
는 스크린 샷입니다
- 두 번째 질문은 스크롤 문제를 방지하기 위해 중첩 스크롤보기에서 일부 recyclerviews를 사용합니다. 모든게 좋지만 kitkat과 같은 안드로이드의 하위 버전에서는 스크롤하는 데 문제가 있습니다 (중첩 된 원인은 SDK<에서 작동하지 않을 수 있습니다). 두 버전 모두 잘 작동하는 일반 scrollview를 사용할 수 있지만 일반 스크롤보기는 코디네이터 레이아웃과 함께 작동하지 않으므로 appbar 레이아웃 숨기기 동작이 제대로 작동하지 않습니다!
이 문제로 제발 도와 줄 수 있습니까?
private ArrayList<Struct> structs;
OnItemListener onItemListener;
private boolean isGrid;
private int Tab;
public Adapter_Recycler(ArrayList<Struct> structs, OnItemListener onItemListener, int Tab, boolean isGrid) {
this.structs = structs;
this.onItemListener = onItemListener;
this.Tab = Tab;
this.isGrid = isGrid;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = null;
if (Tab == 2) {
view = inflater.inflate(R.layout.item_product_color, parent, false);
}
if (Tab == 1 && isGrid == false) {
view = inflater.inflate(R.layout.item_product_list, parent, false);
}
if (Tab == 1 && isGrid) {
view = inflater.inflate(R.layout.item_product_list, parent, false);
}
ViewHolder viewHolder = new ViewHolder(view);
return viewHolder;
}
@Override
public void onBindViewHolder(ViewHolder holder, final int position) {
if (Tab == 2) {
holder.txtHey.setText(structs.get(position).hey);
holder.txtPrice.setText(structs.get(position).hi);
holder.txtHi.setVisibility(View.GONE);
holder.PriceCancel.setVisibility(View.GONE);
holder.txtFinalPrice.setVisibility(View.GONE);
holder.txtHey.setTypeface(Activity_Main.SANS);
holder.txtPrice.setTypeface(Activity_Main.SANS);
Glide
.with(Activity_Main.CONTEXT)
.load(structs.get(position).image)
.placeholder(R.drawable.background_card)
.fitCenter()
.into(holder.banner_image);
}
if (Tab == 1) {
holder.txtHey.setText(structs.get(position).hey);
holder.txtHi.setText(structs.get(position).hi);
holder.txtPrice.setText(structs.get(position).price);
holder.txtFinalPrice.setText(structs.get(position).final_price);
if (holder.txtFinalPrice.getText().toString() == "") {
holder.PriceCancel.setVisibility(View.GONE);
} else {
holder.PriceCancel.setVisibility(View.VISIBLE);
}
holder.txtHey.setTypeface(Activity_Main.SANS);
holder.txtHi.setTypeface(Activity_Main.SANS);
holder.txtPrice.setTypeface(Activity_Main.SANS);
holder.txtFinalPrice.setTypeface(Activity_Main.SANS);
Glide
.with(Activity_Main.CONTEXT)
.load(structs.get(position).image)
.placeholder(R.drawable.background_card)
.fitCenter()
.into(holder.banner_image);
}
holder.linearLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (onItemListener != null) {
onItemListener.onItemSelect(position);
}
}
});
holder.txtHello.setText(structs.get(position).hello);
holder.txtHello.setTypeface(Activity_Main.SANS);
}
@Override
public int getItemCount() {
return structs.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder {
CardView linearLayout;
ImageView banner_image;
TextView txtHey;
TextView txtHi;
TextView txtHello;
TextView txtPrice;
TextView txtFinalPrice;
LinearLayout PriceCancel;
public ViewHolder(View itemView) {
super(itemView);
linearLayout = (CardView) itemView.findViewById(R.id.btn);
banner_image = (ImageView) itemView.findViewById(R.id.banner_image);
txtHey = (TextView) itemView.findViewById(R.id.txtHey);
txtHi = (TextView) itemView.findViewById(R.id.txtHi);
txtHello = (TextView) itemView.findViewById(R.id.txtHello);
txtPrice = (TextView) itemView.findViewById(R.id.txtPrice);
txtFinalPrice = (TextView) itemView.findViewById(R.id.txtFinalPrice);
PriceCancel = (LinearLayout) itemView.findViewById(R.id.price_cancel);
}
}
}
리사이클 러 항목에 xml을 추가 했으므로 'RecyclerView'가 추가 된 위치와 어댑터에 대해 추가하십시오. 또한'RecyclerView ', 즉'LayoutManager','Adapter' 등이 어떻게 설정되었는지를 보여주는 방법을 보여줍니다. 그리고 직면 한 문제와 바람직한 결과를 별도로 진술하십시오. – Abbas
은 참고하시기 바랍니다 : 이러한 속성 cardview'안드로이드 적용되지 않습니다 오리엔테이션 = "수평" 안드로이드 : adjustViewBounds = "true"로 안드로이드 : 패딩 = "8dp"안드로이드 : 배경 = "#의 FFFFFF" ' – k0sh
좋아,하지만하지 이잖아 문제! 저는 cardview를 선형 레이아웃과 viceversa로 변경했습니다. 이러한 추가 속성은 그 때문에 거기에 있습니다! @ k0sh –