slidingdrawer动画速度

我是Android编程的新手,并且会溢出堆栈,因此需要降低我的应用程序中SlidingDrawer的动画速度.

我已经像这样子化了SlidingDrawer:

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;

}

我找到了以下链接How to change animation velocity on SlidingDrawer,它说我可以找到替代实现,或者复制源代码并对其进行修改.

我在自己的项目中创建了SlidingDrawer.java,并粘贴了here代码,但是有错误.有几行引用了R.styleable.SlidingDrawer,例如

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

Eclipse无法解决的问题.

还有四个Eclipse无法解析的成员变量(mTop,mBottom,mLeft和mRight).

如何使Eclipse查找这些资源/变量?然后,我将能够编辑一些变量以使动画速度变慢,对吗?

解决方法:

我相信R.styleable已从sdk中删除,但是您可以编写自己的代码,类似的东西应该可以工作

在values文件夹中创建一个xml文件

<?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文件

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

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

我也在扩展slidedrawer类,这对我有用.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...