2016-11-09 82 views
2

我想加載一個DialogFragment通過單擊recyclerView項目與動畫,但在谷歌搜索小時我不能這樣做。 Recyclerview處於viewPager的frega中。 的dialogFregment是這樣的:動畫與對話框片段Android

public class adsDialogFregment extends DialogFragment { 

public adsDialogFregment(){} 

public static adsDialogFregment newInstance(HashMap<String,String> map) { 
    //HashMap<String,String> map= new HashMap<String, String>(); 

    Bundle args = new Bundle(); 
    args.putSerializable("Map", map); 


    adsDialogFregment fragment = new adsDialogFregment(); 
    fragment.setArguments(args); 
    return fragment; 
} 

@Nullable 
@Override 
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 
    return inflater.inflate(R.layout.fragment_dialog_show_ads,container,false); 
} 

@Override 
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 
    super.onViewCreated(view, savedInstanceState); 

    TextView txtTitle = (TextView)view.findViewById(R.id.txtAdTitle); 
    HashMap<String,String> map= (HashMap<String, String>) getArguments().getSerializable("Map"); 
    txtTitle.setText(map.get("title")); 

} 

@Override 
public void onResume() { 
    /*ViewGroup.LayoutParams params=getDialog().getWindow().getAttributes(); 
    params.height = ViewGroup.LayoutParams.MATCH_PARENT; 
    params.width = ViewGroup.LayoutParams.MATCH_PARENT; 
    getDialog().getWindow().setAttributes((WindowManager.LayoutParams)params);*/ 



    super.onResume(); 
} 

@Override 
public void onActivityCreated(Bundle savedInstanceState) { 
    super.onActivityCreated(savedInstanceState); 
    getDialog().getWindow().getAttributes().windowAnimations= R.style.dialog_slide_animation; 
} 

,這些都是動畫:

<set xmlns:android="http://schemas.android.com/apk/res/android"> 
<scale 
    android:duration="2000" 
    android:fillAfter="false" 
    android:fromXScale="0.5" 
    android:fromYScale="0.5" 
    android:interpolator="@android:anim/linear_interpolator" 
    android:pivotX="50%" 
    android:pivotY="-90%" 
    android:toXScale="1.0" 
    android:toYScale="1.0" /> 

<translate 
    android:duration="3000" 
    android:fromXDelta="-200" 
    android:fromYDelta="-200" 
    android:toXDelta="0" 
    android:toYDelta="0" /> 
</set> 

<set xmlns:android="http://schemas.android.com/apk/res/android"> 
<scale 
    android:duration="20000" 
    android:fillAfter="false" 
    android:fromXScale="1.0" 
    android:fromYScale="1.0" 
    android:interpolator="@android:anim/linear_interpolator" 
    android:pivotX="50%" 
    android:pivotY="-90%" 
    android:startOffset="200" 
    android:toXScale="0.5" 
    android:toYScale="0.5" /> 

<translate 
    android:duration="30000" 
    android:fromXDelta="0" 
    android:fromYDelta="0" 
    android:toXDelta="-200" 
    android:toYDelta="-200" /> 
</set> 

和風格是:

<style name="dialog_slide_animation"> 
    <item name="android:windowEnterAnimation">@anim/slidestart</item> 
    <item name="android:windowExitAnimation">@anim/slideend</item> 
</style> 

但:

dialogFregment.show(fm, "title"); 

不顯示爲動畫對話框。 我想在其他問題都解決方案,但他們沒有工作對我來說

問候

+0

檢查出最佳答案(收到獎金的那個):http://stackoverflow.com/questions/13402782/show-dialogfragment-with-animation-growing-from-a-point –

+0

不適用於DialogFragment 。在@VeneetReddy之前進行測試 – Hamed

回答

1

感謝。 設備上的動畫被解散,這就是原因。

0

對於動畫你必須申請在onCreateDialog方法的風格。我有同樣的問題,然後我在onCreateDialog()中應用了樣式。

@Override 
public Dialog onCreateDialog(final Bundle savedInstanceState) { 

    final RelativeLayout root = new RelativeLayout(getActivity()); 
    root.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); 

    final Dialog dialog = new Dialog(getActivity(),R.style.MyCustomTheme); 
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    dialog.setContentView(root); 
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); 
    dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); 
    return dialog; 
} 

styles.xml

<style name="MyCustomTheme" parent="@android:style/Theme.Panel"> 
    <item name="android:windowAnimationStyle">@style/MyAnimation.Window</item> 
</style> 

<style name="MyAnimation.Window" parent="@android:style/Animation.Activity"> 
    <item name="android:windowEnterAnimation">@anim/anim_in</item> 
    <item name="android:windowExitAnimation">@anim/anim_out</item> 
</style>