gpt4 book ai didi

android - SlidingDrawer 动画速度

转载 作者:太空宇宙 更新时间:2023-11-03 13:36:20 27 4
gpt4 key购买 nike

我是 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 无法解析。

还有四个成员变量(mTop、mBottom、mLeft、mRight)Eclipse无法解析。

如何让 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>

然后在 slider 类中你可以引用xml文件

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

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

我也在扩展 slidingdrawer 类,这对我有用。

关于android - SlidingDrawer 动画速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6884917/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com