Solution 1 :
Try this just change the width of your root frame layout
<FrameLayout xmlns_android="http://schemas.android.com/apk/res/android"
android_layout_width="match_parent"
android_layout_height="wrap_content">
SAMPLE CODE
<?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>
Solution 2 :
Hey as you already have centered the content you can set the dialog’s window to transparent and then show the dialog to remove that white background.
alert.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
alert.show();
Problem :
I want to get an alert dialog view when button clicked like this
<?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>
However at the end when I clicked button I get this image;
It has white backround which one I don’t want to get it and it is not centered. Can anyone help me? Should I use AlertDialog?
My code for AlertDialog is;
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();
Comments
Comment posted by Ahmet B.
I centered it in this way but how can I remove the white backround? Adding android_background=”@android:color/transparent” doesn’t work