2017-05-27 68 views
0

我一直在使用android对话框生成器来扩展其中的布局。一切工作都很好,很完美。但是现在,我想改变对话框构建器的打开方式。我想打开像刷卡那样的对话框生成器。 .i.e。从左到右或从上到下等Android - 以奇特的方式打开对话框生成器

我知道,stackoverflow不是全部关于提问,而是至少显示一些努力。但问题是,我无法找到任何例子或线索。 需要一些建议,或引用要遵循。

谢谢!

对话开幕代码:

final Dialog dialog = new Dialog(main.this); 
    dialog.setContentView(R.layout.prompt_dialoge); 
    dialog.setTitle("Draw your signature below"); 

    Button dialogButton = (Button) dialog.findViewById(R.id.btnOk); 
    // if button is clicked, close the custom dialog 
    dialogButton.setOnClickListener(new View.OnClickListener() 
    { 
     @Override 
     public void onClick(View v) 
     { 
     } 
    }); 
    dialog.show(); 
+0

请添加与显示对话框相关的代码。 –

+0

太容易了。每个人都知道如何打开对话框构建器。我只是想知道如何改变它被打开的方式。我想用刷卡方式打开生成器。而已。 – kamranbhatti585

+1

我只想看看你的代码知道如何创建你的对话框,有很多方法来显示对话框。 –

回答

1

样式添加到您的new Dialog()构造如下图所示。

final Dialog dialog = new Dialog(main.this, R.style.DialogStyle); 
dialog.setContentView(R.layout.prompt_dialoge); 
dialog.setTitle("Draw your signature below"); 

Button dialogButton = (Button) dialog.findViewById(R.id.btnOk); 
// if button is clicked, close the custom dialog 
dialogButton.setOnClickListener(new View.OnClickListener() 
{ 
    @Override 
    public void onClick(View v) 
    { 
    } 
}); 
dialog.show(); 

这种风格添加到您的styles.xml

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <style name="DialogStyle" parent="@android:style/Theme.Dialog"> 
     <item name="android:windowAnimationStyle">@style/DialogAnimation</item> 
    </style> 

    <style name="DialogAnimation"> 
     <item name="android:windowEnterAnimation">@anim/slide_in_right</item> 
     <item name="android:windowExitAnimation">@anim/slide_out_right</item> 
    </style> 
</resources> 

slide_in_right.xml

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

    <translate 
     android:duration="200" 
     android:fillAfter="true" 
     android:fromXDelta="100%p" 
     android:interpolator="@android:anim/linear_interpolator" 
     android:toXDelta="00%p" /> 

</set> 

slide_out_right.xml

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

    <translate 
     android:duration="200" 
     android:fillAfter="true" 
     android:fromXDelta="000%p" 
     android:interpolator="@android:anim/linear_interpolator" 
     android:toXDelta="100%p" /> 

</set> 
+0

动漫文件夹中的动画怎么样?你能给我一个演示代码吗? – kamranbhatti585

+0

@ kamranbhatti585更新了我的答案并添加了动画xml文件内容 –

+0

令人惊叹!谢谢。工作完美。你能告诉我如何摆动slide_in_right.xml中的对话框吗? – kamranbhatti585