Как мне обработать нижний диалог, отрубающий элементы вверху после прокрутки?
Я работаю над приложением, которое использует диалоговое окно нижнего листа для отображения элементов. Нижний лист работает нормально. Но когда текста много и вам нужно прокручивать, верхние элементы обрезаются вверху, а когда вы прокручиваете назад, вы можете видеть, что верхние элементы больше не видны; как будто их отрубили.
Ниже мой xml-код:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:background="#ffffff"
app:cardCornerRadius="20dp"
app:cardElevation="1dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.viewpager.widget.ViewPager
android:id="@+id/dialog_viewpager"
android:layout_width="0dp"
android:layout_height="230dp"
android:layout_gravity="center_horizontal"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/dialog_place_order_button"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:layout_marginStart="24dp"
android:layout_marginLeft="24dp"
android:layout_marginTop="50dp"
android:layout_marginEnd="24dp"
android:layout_marginRight="24dp"
android:layout_marginBottom="16dp"
android:background="@drawable/buttonshape"
android:text="@string/button_text"
android:textColor="#ffffff"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/dialog_item_description" />
<TextView
android:id="@+id/dialog_item_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:fontFamily="@font/montserrat"
android:text="@string/item_select_name"
android:textSize="17sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/dialog_item_price" />
<TextView
android:id="@+id/dialog_item_price"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:fontFamily="@font/montserrat"
android:text="@string/item_select_price"
android:textSize="15sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/dialog_viewpager" />
<TextView
android:id="@+id/textView26"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:fontFamily="@font/montserrat"
android:text="@string/item_select_description"
android:textSize="17sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/dialog_item_name" />
<TextView
android:id="@+id/dialog_item_description"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="3dp"
android:layout_marginEnd="3dp"
android:layout_marginRight="3dp"
android:fontFamily="@font/montserrat"
android:text="@string/long_text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView26" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
`
Ниже мой код для реализации диалогового окна нижнего листа:
final BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(context);
final View view = LayoutInflater.from(context).inflate(R.layout.item_bottom_dialog,
null);
bottomSheetDialog.setContentView(view);
Button catItemButton = bottomSheetDialog.findViewById(R.id.dialog_place_order_button);
ViewPager cat_viewpager = bottomSheetDialog.findViewById(R.id.dialog_viewpager);
TextView cat_item_name, cat_item_price, cat_item_description;
List<String> catItemImages;
catItemImages = new ArrayList<>();
catItemImages.add(image);
catItemImages.add(image2);
catItemImages.add(image3);
cat_item_name = bottomSheetDialog.findViewById(R.id.dialog_item_name);
cat_item_price = bottomSheetDialog.findViewById(R.id.dialog_item_price);
cat_item_description = bottomSheetDialog.findViewById(R.id.dialog_item_description);
assert cat_item_name != null;
cat_item_name.setText(name);
assert cat_item_price != null;
cat_item_price.setText(price);
assert cat_item_description != null;
cat_item_description.setText(description);
ViewPagerAdapter adapter = new ViewPagerAdapter(context, catItemImages);
assert cat_viewpager != null;
cat_viewpager.setAdapter(adapter);
assert catItemButton != null;
catItemButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent paymentIntent = new Intent(context, PaymentActivity.class);
paymentIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Bundle bundle = new Bundle();
bundle.putString("section_item_name", name);
bundle.putString("section_item_price", price);
bundle.putString("section_item_seller_ID", seller_ID);
paymentIntent.putExtras(bundle);
context.startActivity(paymentIntent);
bottomSheetDialog.dismiss();
}
});
((View) view.getParent()).setBackgroundColor(Color.TRANSPARENT);
bottomSheetDialog.show();
<br>Below is an image showing what I mean: