13

DialogAndoridアプリでディスプレイ広告に使用しましたが、これDialogをボトムから約50dpのトップに表示する必要があるため、DialogGravity buttomを設定し、そのボトムマージンを50dpに設定する必要があると思いDialogます。これを解決する方法を教えてください。

XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/popup_element"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/dialogback"
    android:orientation="vertical" >

    <WebView
        android:id="@+id/webView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>

Java:

final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
LayoutInflater inflator = (LayoutInflater) getApplicationContext()
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflator.inflate(R.layout.ad, null, false);
dialog.setContentView(view);
dialog.getWindow().setGravity(Gravity.BOTTOM);
dialog.setCancelable(true);
WebView webView = (WebView) dialog.findViewById(R.id.webView);
webView.loadUrl("");
webView.setWebViewClient(new MyWebViewClient());
webView.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        dialog.dismiss();
    }
});
dialog.show();
4

7 に答える 7

26

同様のスマイリーダイアログを行いました。ダイアログを拡張します

public class SmileCustomDialog extends Dialog {
Context mcontext;
GridView mGridview;

public GridView getGridview() {
    return mGridview;
}

public SmileCustomDialog(final Context context) {
    super(context, R.style.SlideFromBottomDialog);
    this.mcontext = context;
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = inflater.inflate(R.layout.emocategorydialog, null);
    mGridview = (GridView) v.findViewById(R.id.emogrid);
    mGridview.setSelector(new ColorDrawable(Color.TRANSPARENT));

    ImageAdapter mAdapter = new ImageAdapter(mcontext);
    mGridview.setAdapter(mAdapter);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.setContentView(v);

    WindowManager.LayoutParams params = this.getWindow().getAttributes();
    this.setCanceledOnTouchOutside(true);
    params.y = -100;
    this.getWindow().setAttributes(params);

}

}

しかし、肝心なのは

WindowManager.LayoutParams params = yourDialog.getWindow().getAttributes(); // change this to your dialog.

params.y = -100; // Here is the param to set your dialog position. Same with params.x
        yourDialog.getWindow().setAttributes(params);

ダイアログを表示する前にこれを追加するだけです。

于 2012-11-01T08:34:50.260 に答える
3
View view = layoutInflater.inflate(R.layout.dialog_layout, null);
        AlertDialog infoDialog = new AlertDialog.Builder(this)
        .setView(view)  
        .create();
        Window window =infoDialog.getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND );
        WindowManager.LayoutParams wlp = window.getAttributes();
        wlp.gravity = Gravity.BOTTOM;
        wlp.dimAmount=(float) 0.0;
        //wlp.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND ;

        window.setAttributes(wlp);
        infoDialog.show();

重力を下​​に変更

于 2012-11-01T08:36:58.907 に答える
1

私にとって最も効果的だったのは、ダイアログ ビューを FrameLayout 内にラップしてパディングを追加し、onClickListener を「閉じる」ダイアログに設定することでした。このような:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/parentFl"
    android:background="@android:color/transparent"
    android:padding="@dimen/vvlarge_margin">


 dialog?.window?.setBackgroundDrawable(context?.getDrawable(android.R.color.transparent))
 view.parentFl.setOnClickListener { dismiss() }
于 2020-03-18T10:57:20.393 に答える