警报对话框对话框生成器setView在对话框的高度最大时(即拉伸到屏幕 - Android)时裁剪顶部布局

时间:2016-04-27 10:38:14

标签: java android android-layout dialog alertdialog

我创建了一个警告对话框并使用setView 布局高度设置为<ImageView android:id="@+id/iv_close" android:layout_marginTop="10dp" android:layout_marginRight="2dp" android:layout_width="25dp" android:layout_height="25dp" android:layout_gravity="right" android:src="@drawable/close"/> <TextView android:id="@+id/tv_title" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:textSize="20sp" android:textColor="@color/text_color_dark" android:text="Heading/Title i.e. Lorem Ipsum"/> <ScrollView android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="10dp" android:scrollbars="none"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:id="@+id/tv_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="18sp" android:textColor="@color/text_color_dark" android: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 android:id="@+id/btn_ok" android:layout_width="wrap_content" android:layout_height="wrap_content" android:minWidth="100dp" android:minHeight="30dp" android:textSize="18sp" android:layout_marginTop="5dp" android:layout_gravity="center" android:text="Ok"/> </LinearLayout> </ScrollView>

当对话框中的文字足以填满屏幕时,对话框将裁剪顶视图。

普通文字
enter image description here

大文字
enter image description here

对话框布局的XML:

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;

对话的Java代码:

<meta-data
    android:name="AA_MODELS"
    android:value="com.myapp.model.Item, com.myapp.model.Category" />

0 个答案:

没有答案