java Alert Dialog Builder setView在对话框高度达到最大值(即延伸至屏幕)时裁剪顶部布局
我已经创建了一个警报对话框并使用setView
布局高度设置为wrap_content
当对话框中的文本足以填满屏幕时,对话框将裁剪俯视图
对话框布局的XML:
<ImageView
安卓:id="@+id/iv_close"
安卓:layout_marginTop="10dp"
安卓:layout_marginRight="2dp"
安卓:layout_width="25dp"
安卓:layout_height="25dp"
安卓:layout_gravity="right"
安卓:src="@drawable/close"/>
<TextView
安卓:id="@+id/tv_title"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:gravity="center"
安卓:textSize="20sp"
安卓:textColor="@color/text_color_dark"
安卓:text="Heading/Title i.e. Lorem Ipsum"/>
<ScrollView
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:padding="10dp"
安卓:scrollbars="none">
<LinearLayout
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:orientation="vertical">
<TextView
安卓:id="@+id/tv_text"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:textSize="18sp"
安卓:textColor="@color/text_color_dark"
安卓:text="Lorem Ipsum is simply dummysoftware like Aldus PageMaker including versions of Lorem Ipsum dummysoftware like Aldus PageMaker including versions of Lorem Ipsum dummysoftware like Aldus PageMaker including versions of Lorem Ipsum dummysoftware like Aldus PageMaker including versions of Lorem Ipsum dummysoftware like Aldus PageMaker including versions of Lorem Ipsum dummysoftware like Aldus PageMaker including versions of Lorem Ipsum dummysoftware like Aldus PageMaker including versions of Lorem Ipsum dummysoftware like Aldus PageMaker including versions of Lorem Ipsum dummysoftware like Aldus PageMaker including versions of Lorem Ipsum ."/>
<uk.org.humanfocus.hfi.CustomViews.ButtonColorDark
安卓:id="@+id/btn_ok"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:minWidth="100dp"
安卓:minHeight="30dp"
安卓:textSize="18sp"
安卓:layout_marginTop="5dp"
安卓:layout_gravity="center"
安卓:text="Ok"/>
</LinearLayout>
</ScrollView>
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(new ContextThemeWrapper(context, R.style.AppDialogTheme));
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
View dialog = inflater.inflate(R.layout.dialog_display_information, null);
dialogBuilder.setView(dialog);
dialogBuilder.setCancelable(false);
final AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show();
((TextView)dialog.findViewById(R.id.tv_title)).setText(title);
((TextView)dialog.findViewById(R.id.tv_text)).setText(text);
dialog.findViewById(R.id.btn_ok).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.cancel();
}
});
dialog.findViewById(R.id.iv_close).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.cancel();
}
});
return alertDialog;
共 (0) 个答案