<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/popup_img"
android:contentDescription="@string/todo" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="32dp"
android:orientation="vertical">
// TextView's
</LinearLayout>
<FrameLayout
android:id="@+id/btn_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom">
<ImageView
// />
<TextView
// />
</FrameLayout>
</FrameLayout>
然而,在最后当我点击按钮,我得到这个图像。
它有白色的背景,我不希望得到它,它是不居中。谁能帮帮我?我应该使用AlertDialog吗?
我的AlertDialog的代码是
AlertDialog.Builder builder = new AlertDialog.Builder(this);
View view = getLayoutInflater().inflate(R.layout.layout_congratulations, null);
builder.setView(view);
AlertDialog alert = builder.create();
alert.show();
试试这个,只要改变你的根框架布局的宽度就可以了
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
示例代码
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/popup_img"
android:contentDescription="@string/todo" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="32dp"
android:orientation="vertical">
// TextView's
</LinearLayout>
<FrameLayout
android:id="@+id/btn_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom">
<ImageView
// />
<TextView
// />
</FrameLayout>
</FrameLayout>
嘿既然你已经将内容居中了,你可以将对话框的窗口设置为透明,然后再显示对话框,去掉那个白色背景。
alert.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
alert.show();