SlidingDrawer动画速度 [英] SlidingDrawer animation velocity

查看:277
本文介绍了SlidingDrawer动画速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的Andr​​oid编程和堆栈溢出,我需要在我的应用程序减慢SlidingDrawer的动画速度。

I'm new to Android programming and to stack overflow, and I need to slow down the animation speed of a SlidingDrawer in my app.

我已经子类SlidingDrawer是这样的:

I've already subclassed SlidingDrawer like this:

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.SlidingDrawer;

public class WrappingSlidingDrawer extends SlidingDrawer {

public WrappingSlidingDrawer(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    int orientation = attrs.getAttributeIntValue("android", "orientation", ORIENTATION_VERTICAL);
    mTopOffset = attrs.getAttributeIntValue("android", "topOffset", 0);
    mVertical = (orientation == SlidingDrawer.ORIENTATION_VERTICAL);
}

public WrappingSlidingDrawer(Context context, AttributeSet attrs) {
    super(context, attrs);

    int orientation = attrs.getAttributeIntValue("android", "orientation", ORIENTATION_VERTICAL);
    mTopOffset = attrs.getAttributeIntValue("android", "topOffset", 0);
    mVertical = (orientation == SlidingDrawer.ORIENTATION_VERTICAL);
}


@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

    int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
    int widthSpecSize =  MeasureSpec.getSize(widthMeasureSpec);

    int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec);
    int heightSpecSize =  MeasureSpec.getSize(heightMeasureSpec);

    if (widthSpecMode == MeasureSpec.UNSPECIFIED || heightSpecMode == MeasureSpec.UNSPECIFIED) {
        throw new RuntimeException("SlidingDrawer cannot have UNSPECIFIED dimensions");
    }

    final View handle = getHandle();
    final View content = getContent();
    measureChild(handle, widthMeasureSpec, heightMeasureSpec);

    if (mVertical) {
        int height = heightSpecSize - handle.getMeasuredHeight() - mTopOffset;
        content.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(height, heightSpecMode));
        heightSpecSize = handle.getMeasuredHeight() + mTopOffset + content.getMeasuredHeight();
        widthSpecSize = content.getMeasuredWidth();
        if (handle.getMeasuredWidth() > widthSpecSize) widthSpecSize = handle.getMeasuredWidth();
    }
    else {
        int width = widthSpecSize - handle.getMeasuredWidth() - mTopOffset;
        getContent().measure(MeasureSpec.makeMeasureSpec(width, widthSpecMode), heightMeasureSpec);
        widthSpecSize = handle.getMeasuredWidth() + mTopOffset + content.getMeasuredWidth();
        heightSpecSize = content.getMeasuredHeight();
        if (handle.getMeasuredHeight() > heightSpecSize) heightSpecSize = handle.getMeasuredHeight();
    }

    setMeasuredDimension(widthSpecSize, heightSpecSize);
}

private boolean mVertical;
private int mTopOffset;

}

我发现这个链接:如何更改SlidingDrawer <动画速度/一>,和它说,我能找到一个替代实现,或者复制源和修改。

I found this link: How to change animation velocity on SlidingDrawer, and it says that I can find an alternative implementation, or copy the source and modify it.

我在自己的项目中创建SlidingDrawer.java和<一个粘贴的code href="http://www.java2s.com/Open-Source/Android/android-core/platform-frameworks-base/android/widget/SlidingDrawer.java.htm"相对=nofollow>此处,但有错误。有引用R.styleable.SlidingDrawer,如几行

I created SlidingDrawer.java in my own project and pasted the code from here, but there are errors. There are several lines that reference R.styleable.SlidingDrawer, e.g.

TypedArray a = context.obtainStyledAttributes(attrs,
            R.styleable.SlidingDrawer, defStyle, 0);

而Eclipse中无法解析。

which Eclipse can't resolve.

另外还有四个成员变量(mTop,mBottom,MLEFT,mRight),它的Eclipse解决不了。

There are also four member variables (mTop, mBottom, mLeft, mRight) which Eclipse can't resolve.

我如何让Eclipse中找到这些资源/变量?那么我就可以编辑一些变量导致较慢的动画,对吧?

How do I make Eclipse find these resources/variables? I will then be able to edit some variables to result in a slower animation, right?

推荐答案

我相信R.styleable从SDK中删除,你可以写你自己的,虽然,这样的事情应该工作

I believe R.styleable was removed from the sdk, you can write your own though, something like this should work

在值文件夹中创建一个XML文件

In the values folder create an xml file

<?xml version="1.0" encoding="UTF-8"?>
<resources>
<declare-styleable name="MySlider"> 
        <attr name = "SlidingDrawer_orientation"  format="integer"/>
        <attr name = "SlidingDrawer_bottomOffset" format = "dimension"/>
        <attr name = "SlidingDrawer_topOffset" format = "dimension"/>
        <attr name = "SlidingDrawer_allowSingleTap" format = "boolean"/>
        <attr name = "SlidingDrawer_animateOnClick" format = "boolean"/>
        <attr name = "SlidingDrawer_handle" format = "reference"/>
        <attr name = "SlidingDrawer_content" format = "reference"/>
    </declare-styleable>
</resources>

然后在滑块类,你可以参考的XML文件

Then in the slider class you can reference the xml file

TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MySlider, defStyle, 0);

int orientation = a.getInt(R.styleable.MySlider_SlidingDrawer_orientation, ORIENTATION_VERTICAL);
//...etc. ...

我也扩展slidingdrawer类,这对我的作品。

I am also extending the slidingdrawer class and this works for me.

这篇关于SlidingDrawer动画速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆