我设计了布局,但ScrollView出现问题。特别是,我在此ScrollView中有一个ScrollView和RecyclerView。当我在RecyclerView的最后一行中选择项目时,View不会停留在最后一行,它会向上移动到上一行。例如,我的视图有4行。当我在第四行中选择一个项目时,视图将自动上移至第三行。因此,如何防止出现这种情况,以便当我在最后一行中选择项目时,视图将保留并且不会向上移动?谢谢
布局:
<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>
适配器:
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);
}
}
什么会阻止他们?什么时候会发生性侵犯和催眠程序?他们的领导何时会为他们的罪行付款?什么时候他们的帐户会被挂起,而主帐户会被挂起?
请参阅节制理论以获取关于节制理念的信息。
[Aaron Hall♦美国纽约市222k6161金徽章330330银徽章285285青铜徽章当选2016年
[安迪♦36.7k2222金徽章123123银徽章186186青铜徽章当选2017年
Baum mit Augen♦44.1k1212金徽章125125银徽章162162青铜徽章当选2019年
[Bhargav Rao♦印度卡纳塔克邦班加罗尔34.4k2222金徽章101101银徽章118118青铜徽章当选2016年
[Bohemian♦澳大利亚墨尔本326k7272金徽章463463银徽章601601青铜徽章当选2014年
[BoltClock♦新加坡568k134134金徽章12301230银徽章12481248青铜徽章当选2011年
[布拉德·拉尔森♦威斯康星州麦迪逊166k4545金徽章378378银徽章556556青铜徽章当选2012年
ChrisF♦英国120k2525金徽章230230银徽章304304青铜徽章当选2013年
Cody Gray♦美国加利福尼亚州桑尼维尔206k3838金牌418418银牌495495青铜牌当选2017年
[cece德国432k6969金徽章601601银徽章745745青铜徽章当选2016年
[Flexo♦76.5k2222金徽章163163银徽章241241青铜徽章当选2013年
[Jean-FrançoisFabre♦法国图卢兹116k1010金徽章7777银徽章133133青铜徽章当选2019年
josliber♦密歇根州39.5k1111金徽章7373银徽章109109青铜徽章当选2015年
[Madara Uchiha♦以色列146k4949金徽章229229银徽章280280青铜徽章当选2015年
[Martijn Pieters♦英国剑桥784k180180金徽章28812881银徽章25712571青铜徽章当选2015年
meagar♦192k3434金徽章290290银徽章304304青铜徽章当选2015年
[Michael Myers♦美国166k4040金徽章268268银徽章284284青铜徽章指定于2010年7月11日] >>
Rob♦澳大利亚23.8k1313金徽章6565银徽章8080青铜徽章当选2018年
[Ry-♦加拿大不列颠哥伦比亚省维多利亚市183k4343金徽章371371银徽章387387青铜徽章当选2013年
[Samuel Liew♦澳大利亚新南威尔士州59.6k3939金牌124124银牌191191青铜牌当选2019年
撤消♦24.6k2121金徽章9696银徽章