AlertDialog并不直接支持scrollView,所以你需要一个CustomDialog.
public class CustomDialog extends Dialog {
public CustomDialog(@NonNull Context context) {
super(context);
init(context);
}
private void init(Context context) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.custom_dialog_layout);
ScrollView scrollView = findViewById(R.id.scrollView);
// Add your views or set up the ScrollView as needed
getWindow().setLayout(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
);
// Set any other properties or listeners as needed
}
}
像下面这样实例化它
CustomDialog customDialog = new CustomDialog(context);
customDialog.show();
您的滚动视图
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<!-- Your content inside the ScrollView goes here -->
</ScrollView>
</LinearLayout>