Saeid Saeid - 7 days ago 6
Android Question

android Dialog Gravity

I'm trying to make a guide for my app.

i create a dialog that appear after 500ms and show the layout that have a image-view.

all thing is good Except Gravity.

i need to dialog.getWindow().setGravity(Gravity.BOTTOM); but in app, not apply this code.




void temp_help()
{
new Handler().postDelayed(new Thread()
{
@Override
public void run(){
final Dialog dialog = new Dialog(personal_view_MainActivity.this,android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCancelable(true);
dialog.setContentView(R.layout.view_temp_help);
dialog.setTitle(" راهنما ");

dialog.getWindow().setGravity(Gravity.BOTTOM);



dialog.show();

ImageView imageView=(ImageView)dialog.findViewById(R.id.imghelp_view);
imageView.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
dialog.setContentView(R.layout.view_temp_help2);
}
});
}
}, 500);
preferences.set_url("main_temp_help", "visited");
}

Answer

Here is my method:

I had to run my app in multi-size and dialog. Should be full screen, I can't have a specified size for my image - so , I used from FrameLayout in match_parent mode that make my image(Dialog) full screen.

Code below:


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<FrameLayout
    android:id="@+id/FrameLayout3"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:background="@drawable/my-image-in-any-size"
    android:alpha=".87">
</FrameLayout>