3

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;

}

このリンクを見つけました: SlidingDrawerでアニメーション速度を変更する方法 、別の実装を見つけるか、ソースをコピーして変更できると書かれています。

自作プロジェクトで SlidingDrawer.java を作成し、ここからコードを貼り付けたのですが、エラーが出てしまいます。R.styleable.SlidingDrawer を参照する行がいくつかあります。

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

Eclipse では解決できません。

Eclipse が解決できない 4 つのメンバー変数 (mTop、mBottom、mLeft、mRight) もあります。

Eclipse にこれらのリソース/変数を見つけさせるにはどうすればよいですか? その後、いくつかの変数を編集して、アニメーションを遅くすることができますよね?

4

1 に答える 1

4

R.styleableがSDKから削除されたと思いますが、独自に作成することもできますが、このようなものは機能するはずです。

値フォルダーに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. ...

私はslidingdrawerクラスも拡張していますが、これは私にとってはうまくいきます。

于 2011-07-31T21:21:53.943 に答える