2011-07-30 5 views
3

Androidプログラミングの新機能で、オーバーフローをスタックするために、私のアプリでSlidingDrawerのアニメーションの速度を遅くする必要があります。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が解決できない4つのメンバー変数(mTop、mBottom、mLeft、mRight)もあります。

Eclipseにこれらのリソース/変数を見つける方法を教えてください。私は、より遅いアニメーションになるようにいくつかの変数を編集することができますよね?スライダーで次に

+0

ちょっと、最終的なカスタムクラスを提供してください。そして、それは私にエラー "InflateException"を与えているので、XMLにどのように追加するのですか? – abhishek

答えて

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ファイルを参照することができます

また、私はslidesdrawerクラスを拡張しています。

+0

ありがとう!これは私の問題を解決し、私は今クラスを拡張することができます。 –

+0

どのようにメンバー変数の問題を解決しましたか? –

+0

'getTop()'、 'getBottom()'など、 'mTop'、' mBottom'などのgetterを使うことを意味しますか? – triggs

関連する問題