之前账号的文章2:Context-menu.Android库的使用(修改显示位置)

来源:互联网 发布:迈越网络刀塔传奇 编辑:程序博客网 时间:2024/05/29 10:38

这个库iOS版可以直接调用一个改变位置的方法即可,但Android需要修改相关源码,我是修改为右下显示,解决方法:

1.修改fragment_menu:

<LinearLayout    android:id="@+id/wrapper_buttons"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:orientation="vertical"    android:layout_alignParentRight="true"    android:layout_alignParentBottom="true"    android:layout_alignParentEnd="true"/><LinearLayout    android:id="@+id/wrapper_text"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:orientation="vertical"    android:layout_toLeftOf="@+id/wrapper_buttons"    android:layout_toStartOf="@+id/wrapper_buttons"    android:layout_alignParentBottom="true"    android:layout_marginRight="@dimen/text_wrapper_right_margin"    android:layout_marginEnd="@dimen/text_wrapper_right_margin"    android:gravity="end" />
2.修改menuAdapter,我这里只用修改3个位置:

1.

private void resetAnimations() {    for (int i = 0; i < getItemCount(); i++) {        resetTextAnimation(mTextWrapper.getChildAt(i));        if (i == getItemCount()-1) {            resetSideAnimation(mMenuWrapper.getChildAt(i));        } else {            resetVerticalAnimation(mMenuWrapper.getChildAt(i), true);        }    }}
2.
private AnimatorSet setOpenCloseAnimation(boolean isCloseAnimation) {    List<Animator> textAnimations = new ArrayList<>();    List<Animator> imageAnimations = new ArrayList<>();    //true就是隐藏,从大到小隐藏。    if (isCloseAnimation) {        for (int i = getItemCount() - 1; i >= 0; i--) {            fillOpenClosingAnimations(true, textAnimations, imageAnimations, i);        }    } else {        //显示从后往前显示        for (int i = getItemCount() - 1; i >= 0; i--) {            fillOpenClosingAnimations(false, textAnimations, imageAnimations, i);        }    }
3.
private void fillOpenClosingAnimations(boolean isCloseAnimation, List<Animator> textAnimations, List<Animator> imageAnimations, int wrapperPosition) {    AnimatorSet textAnimatorSet = new AnimatorSet();    Animator textAppearance = isCloseAnimation ?            AnimatorUtils.alfaDisappear(mTextWrapper.getChildAt(wrapperPosition))            : AnimatorUtils.alfaAppear(mTextWrapper.getChildAt(wrapperPosition));    Animator textTranslation = isCloseAnimation ?            AnimatorUtils.translationRight(mTextWrapper.getChildAt(wrapperPosition), mContext.getResources().getDimension(R.dimen.text_right_translation))            : AnimatorUtils.translationLeft(mTextWrapper.getChildAt(wrapperPosition), mContext.getResources().getDimension(R.dimen.text_right_translation));    textAnimatorSet.playTogether(textAppearance, textTranslation);    textAnimations.add(textAnimatorSet);    Animator imageRotation = isCloseAnimation ?            wrapperPosition == 0 ? AnimatorUtils.rotationCloseToRight(mMenuWrapper.getChildAt(wrapperPosition)) : AnimatorUtils.rotationCloseVertical(mMenuWrapper.getChildAt(wrapperPosition))            : wrapperPosition == getItemCount()-1 ? AnimatorUtils.rotationOpenFromRight(mMenuWrapper.getChildAt(wrapperPosition)) : AnimatorUtils.rotationOpenVertical(mMenuWrapper.getChildAt(wrapperPosition));    imageAnimations.add(imageRotation);}
完工。。。。。
0 0