卓凡姓黎 2016-06-07 14:58 采纳率: 100%
浏览 1180

Android位移动画在索尼手机上实现不了

动画问题描述如下:
点击一个按钮就展示一个带三个button的PopupWindow,PopupWindow展示后就把button从底部弹出到屏幕中间,可是只有索尼手机显示不到这个动画,然后在dismiss之前展示从屏幕中间弹出到顶部的动画,这个动画却可以实现但是之后PopupWindow却没有dismiss掉。这会跟内存占用过多而实现不到吗?还是有什么原因?

这个是我封装的PopupWindow类

 package com.xxxxxx.xxxxxx.widget;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.os.Handler;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.PopupWindow;

import com.xxxxxx.xxxxxx.R;

public class ButtonsPopupWindow extends PopupWindow implements
        View.OnClickListener
{
    private Animation photoEnterAnim;

    private Animation firstExistAnim;

    private Button photoBtn;

    private Animation gifEnterAnim;

    private Animation secondExistAnim;

    private Button gifBtn;

    private Animation streamEnterAnim;

    private Animation thirdExistAnim;

    private Button streamBtn;

    private int selectedBtn;

    private boolean canStartAnim = true;

    private ThreeButtonsListener listener;

    public ButtonsPopupWindow(Context context, ThreeButtonsListener listener)
    {
        super(context);
        this.listener = listener;
        initView(context);
    }

    private void initView(Context context)
    {
        LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View otherView = layoutInflater.inflate(R.layout.item_camera_select,
                null);
        otherView.setOnTouchListener(new View.OnTouchListener()
        {
            @Override
            public boolean onTouch(View v, MotionEvent event)
            {
                if (event.getAction() == MotionEvent.ACTION_DOWN)
                {
                    startExistAnim();
                }
                return true;
            }
        });

        photoBtn = (Button) otherView.findViewById(R.id.btn_goto_camera);
        photoBtn.setOnClickListener(this);
        gifBtn = (Button) otherView.findViewById(R.id.btn_camera_gif);
        gifBtn.setOnClickListener(this);
        streamBtn = (Button) otherView.findViewById(R.id.btn_camera_live);
        streamBtn.setOnClickListener(this);

        photoEnterAnim = AnimationUtils.loadAnimation(context,
                R.anim.three_button_enter_second);
        gifEnterAnim = AnimationUtils.loadAnimation(context,
                R.anim.three_button_enter_first);
        streamEnterAnim = AnimationUtils.loadAnimation(context,
                R.anim.three_button_enter_third);
        firstExistAnim = AnimationUtils.loadAnimation(context,
                R.anim.three_button_exist_first);
        secondExistAnim = AnimationUtils.loadAnimation(context,
                R.anim.three_button_exist_second);
        thirdExistAnim = AnimationUtils.loadAnimation(context,
                R.anim.three_button_exist_third);

        // 最后一个退出动画完成后把PopupWindowDismiss掉
        thirdExistAnim.setAnimationListener(new Animation.AnimationListener()
        {
            @Override
            public void onAnimationStart(Animation animation)
            {
            }

            @Override
            public void onAnimationEnd(Animation animation)
            {
                // 这样就解决了三星的一些机型的动画出错问题
                new Handler().post(new Runnable()
                {
                    @Override
                    public void run()
                    {
                        ButtonsPopupWindow.this.dismiss();
                    }
                });
            }

            @Override
            public void onAnimationRepeat(Animation animation)
            {
            }
        });

        this.setContentView(otherView);
        this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        this.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        // 因为某些机型是虚拟按键的,所以要加上以下设置防止挡住按键.
        this.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        ColorDrawable dw = new ColorDrawable(ContextCompat.getColor(context,
                R.color.main_window_background));
        this.setBackgroundDrawable(dw);
    }

    @Override
    public void dismiss()
    {
        super.dismiss();
        listener.onButtonClick(selectedBtn);
    }

    // 显示退出动画
    public void startExistAnim()
    {
        if (canStartAnim) // 防止快速点击显示多次动画
        {
            canStartAnim = false;
            gifBtn.startAnimation(firstExistAnim);
            photoBtn.startAnimation(secondExistAnim);
            streamBtn.startAnimation(thirdExistAnim);
        }
    }

    @Override
    public void onClick(View v)
    {
        selectedBtn = v.getId();
        startExistAnim();
    }

    // 显示PopupWindow的时候就显示动画
    @Override
    public void showAtLocation(View parent, int gravity, int x, int y)
    {
        super.showAtLocation(parent, gravity, x, y);
        selectedBtn = 0;
        canStartAnim = true;
        gifBtn.startAnimation(gifEnterAnim);
        photoBtn.startAnimation(photoEnterAnim);
        streamBtn.startAnimation(streamEnterAnim);
    }

    public interface ThreeButtonsListener
    {
        void onButtonClick(int buttonId);
    }
}

这个是布局文件

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="horizontal">

        <Button
            android:id="@+id/btn_goto_camera"
            android:layout_width="@dimen/item_camera_select_btn"
            android:layout_height="@dimen/item_camera_select_btn"
            android:background="@mipmap/new_media_icon_1" />

        <Button
            android:id="@+id/btn_camera_gif"
            android:layout_width="@dimen/item_camera_select_btn"
            android:layout_height="@dimen/item_camera_select_btn"
            android:layout_marginLeft="@dimen/btn_camera_gif_distance"
            android:layout_marginRight="@dimen/btn_camera_gif_distance"
            android:background="@mipmap/new_media_icon_2" />

        <Button
            android:id="@+id/btn_camera_live"
            android:layout_width="@dimen/item_camera_select_btn"
            android:layout_height="@dimen/item_camera_select_btn"
            android:background="@mipmap/new_media_icon_3" />
    </LinearLayout>

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

    <translate
        android:duration="500"
        android:fromYDelta="0"
        android:startOffset="200"
        android:toYDelta="-100%p" />

    <alpha
        android:duration="500"
        android:fromAlpha="1.0"
        android:startOffset="200"
        android:toAlpha="0.0" />

</set>

请问有大神可以给出意见吗?非常感谢!

  • 写回答

1条回答 默认 最新

  • 普通网友 2016-10-05 16:11
    关注

    super(context);
    this.listener = listener;
    initView(context);
    }

    private void initView(Context context)
    {
        LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View otherView = layoutInflater.inflate(R.layout.item_camera_select,
                null);
        otherView.setOnTouchListener(new View.OnTouchListener()
        {
            @Override
            public boolean onTouch(View v, MotionEvent event)
            {
                if (event.getAction() == MotionEvent.ACTION_DOWN)
                {
                    startExistAnim();
                }
                return true;
            }
        });
    
        photoBtn = (Button) otherView.findViewById(R.id.btn_goto_camera);
        photoBtn.setOnClickListener(this);
        gifBtn = (Button) otherView.findViewById(R.id.btn_camera_gif);
        gifBtn.setOnClickListener(this);
        streamBtn = (Button) otherView.findViewById(R.id.btn_camera_live);
        streamBtn.setOnClickListener(this);
    
        photoEnterAnim = AnimationUtils.loadAnimation(context,
                R.anim.three_button_enter_second);
        gifEnterAnim = AnimationUtils.loadAnimation(context,
                R.anim.three_button_enter_first);
        streamEnterAnim = AnimationUtils.loadAnimation(context,
                R.anim.three_button_enter_third);
        firstExistAnim = AnimationUtils.loadAnimation(context,
                R.anim.three_button_exist_first);
        secondExistAnim = AnimationUtils.loadAnimation(context,
                R.anim.three_button_exist_second);
        thirdExistAnim = AnimationUtils.loadAnimation(context,
                R.anim.three_button_exist_third);
    
        // 最后一个退出动画完成后把PopupWindowDismiss掉
        thirdExistAnim.setAnimationListener(new Animation.
    
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料