标题翻译
Custom alert dialog view does not show things set dynamically
问题
我已经创建了一个警示对话框,其中显示了一个自定义视图,
Java代码
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.about_me_alert, null);
CircleImageView imageView = view.findViewById(R.id.image);
Glide.with(view).load("https://example.com/example.jpg").into(imageView);
TextView title = view.findViewById(R.id.title);
title.setText("This is a title");
TextView note = view.findViewById(R.id.note);
note.setText("This is a note");
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setView(view);
builder.setPositiveButton("Okay", (dialog, which) -> dialog.dismiss()).show();
XML布局 - about_me_alert.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/cardbackground"
android:orientation="vertical">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/image"
android:layout_width="128dp"
android:layout_height="128dp"
android:layout_centerHorizontal="true"
android:layout_margin="8dp" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/image"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp"
android:textColor="@color/white"
android:textSize="16sp" />
<TextView
android:id="@+id/note"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/title"
android:layout_centerHorizontal="true"
android:layout_margin="8dp"
android:textColor="@color/white"
android:textSize="16sp" />
</RelativeLayout>
当警示对话框显示时,它为ImageView和两个TextView预留了空间,但没有设置文本或图像。
注意:这仅在我为发布制作生产APK时发生,而在我手机上进行测试时不会出现这种情况。
英文翻译
I have made an alert dialog which shows a custom view,
Java Code
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.about_me_alert, null);
CircleImageView imageView = view.findViewById(R.id.image);
Glide.with(view).load("https://example.com/example.jpg").into(imageView);
TextView title = view.findViewById(R.id.title);
title.setText("This is a title");
TextView note = view.findViewById(R.id.note);
note.setText("This is a note");
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setView(view);
builder.setPositiveButton("Okay", (dialog, which) -> dialog.dismiss()).show();
XML Layout- about_me_alert.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/cardbackground"
android:orientation="vertical">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/image"
android:layout_width="128dp"
android:layout_height="128dp"
android:layout_centerHorizontal="true"
android:layout_margin="8dp" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/image"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp"
android:textColor="@color/white"
android:textSize="16sp" />
<TextView
android:id="@+id/note"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/title"
android:layout_centerHorizontal="true"
android:layout_margin="8dp"
android:textColor="@color/white"
android:textSize="16sp" />
</RelativeLayout>
When alert is shown, it reserves space for the imageview, and two textviews but does not set text or image.
NOTE: This only happens when I make a production apk for release, not while I am testing on my phone.
专注分享java语言的经验与见解,让所有开发者获益!
评论