我想夸大一个将成为我的“无网络对话框”的视图。我创建了一个自定义布局,我现在想要膨胀和显示。我遇到的冲突是动画不起作用。我希望对话框从屏幕底部滑入中间,然后在结束时弹回。这是我正在使用的。
styles.xml
<!-- animation for network dialog -->
<style name="DialogSlideAnim" parent="@android:style/Theme.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowAnimationStyle">@style/DialogAnimation</item>
</style>
<style name="DialogAnimation">
<item name="android:windowEnterAnimation">@anim/slide_up_bounce</item>
<item name="android:windowExitAnimation">@anim/fade_out</item>
</style>
这是我的slide_up_bounce.xml
<scale
android:duration="600"
android:fromXScale="1"
android:fromYScale="0.5"
android:pivotX="50%"
android:pivotY="0%"
android:toXScale="1.0"
android:toYScale="1.0" />
<alpha
android:duration="600"
android:fromAlpha="0.0"
android:toAlpha="1.0" />
<translate
android:duration="600"
android:fromYDelta="50%"
android:toYDelta="0%" />
在Utility类中,我有一个类似于
的方法public static void networkDialog(Context context) {
final Dialog dialog = new Dialog(context, R.style.DialogAnimation);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.dialog_network, null);
dialog.setContentView(view);
ImageButton ibRefresh = (ImageButton) view.findViewById(R.id.ib_refresh);
}
此刻,对话框立即显示,没有滑动或弹跳。我该如何解决这个问题,或者我应该采取不同的方法来实现这一目标?提前谢谢!
答案 0 :(得分:1)
我想出了如何做到这一点。而不是使用Dialog,最好使用DialogFragment。无论出于何种原因,我的Dialog实现是正确的,它只是不适用于动画。这是我的实施:
public class NetworkDialog extends DialogFragment {
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(STYLE_NO_FRAME, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
}
@Override
public void onActivityCreated(Bundle arg0) {
super.onActivityCreated(arg0);
getDialog().getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
}
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
final View v = inflater.inflate(R.layout.dialog_network, container, false);
v.setAlpha(0.5f);
final ImageButton ibRefresh = (ImageButton) v.findViewById(R.id.ib_refresh);
ibRefresh.setClickable(true);
ibRefresh.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MapActivity.rotateImageView(ibRefresh);
}
});
return v;
}
@Override
public void onResume() {
super.onResume();
}
@Override
public void onPause() {
super.onPause();
}
}
然后我用
调用对话框NetworkDialog dialogFragment = new NetworkDialog();
dialogFragment.show(getFragmentManager(), "ProgressDialog");
答案 1 :(得分:0)
解决方案是将样式作为 Dialog
参数传递,如下所示:
Dialog confirm = new Dialog(context, R.style.BottomSheetDialog);
<style name="BottomSheetDialog" parent="Theme.Design.Light.BottomSheetDialog">
<item name="bottomSheetStyle">@style/bottomSheetStyleWrapper</item>
</style>
<style name="bottomSheetStyleWrapper" parent="Widget.Design.BottomSheet.Modal">
<item name="android:background">@android:color/transparent</item>
</style>