안녕하세요.

 

안드로이드 SlidingDrawer를 사용하여 온 오프 버튼을 구현하는데 문제가 있습니다.

 

기본적으로 드래그, 터치 등으로 온 오프 Sliding 은 잘 됩니다.

 

하지만 animationOpen(), animationClose() 동작 시, 즉, Toggle시 애니메이션 속도가 좀 빠르기에

 

이 속도를 느리게 조절하고자 합니다.

 

제가 찾아본 바로는 SlidingDrawer API 도 없고, XML Layout에도 애니메이션 속도에 대해 접근할 수 없더군요.

 

SlidingDrawer.java 소스를 받아서 확인해 보니 속도에 대한 값은 아래와 같이 Hard Code 되어 있더군요...

 

 private static final float MAXIMUM_TAP_VELOCITY = 100.0f;
 private static final float MAXIMUM_MINOR_VELOCITY = 150.0f;
 private static final float MAXIMUM_MAJOR_VELOCITY = 200.0f;
 private static final float MAXIMUM_ACCELERATION = 2000.0f;
 private static final int VELOCITY_UNITS = 1000;
 private static final int MSG_ANIMATE = 1000;
 private static final int ANIMATION_FRAME_DURATION = 1000 / 60;

 

이렇게 폐쇄적일 수가...OTL...

 

그래서 이 소스를 가져다가 위 부분을 수정하여 사용하려고 하는데 SlideingDrawer 생성자 부분에서

아래의 부분에서 Handle ID 값을 계속 못받아와서 에러가 발생됩니다. (throw new IllegalArgumentException)

 

 int handleId = a.getResourceId(R.styleable.MySlider_SlidingDrawer_handle, 0);
        if (handleId == 0) {
            throw new IllegalArgumentException("The handle attribute is required and must refer "
                    + "to a valid child.");
        }

 

아래는 XML Layout입니다.

 

<LinearLayout
         android:id="@+id/slideBtnLayout"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_marginTop="15dip">


       <kr.co.lguplus.applauncher2.utils.SlideButton
               android:id="@+id/slideOnOff"
               android:layout_gravity="right|center_vertical"
               android:content="@+id/slideContentLayout"
               android:handle="@+id/slideHandle"
               android:layout_width="66dip"
               android:layout_height="27.7dip"
               android:layout_marginLeft="212dip"
               android:layout_alignParentRight="true"
               android:orientation="horizontal"
               android:background="@drawable/btn_bg_on">
       
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/slideHandle"
            android:background="@drawable/btn_onoff_off"/>
        
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:background="@drawable/btn_bg_off"
            android:id="@+id/slideContentLayout">
        </LinearLayout>
     </kr.co.lguplus.applauncher2.utils.SlideButton>    
     <ImageView
         android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginLeft="-1.32dip"
          android:background="@drawable/btn_bg_onoff_frame"/>
      </LinearLayout>

 

그리고 Attribute를 리소스에 정의한 내용은 아래입니다.

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

찾아보니  xmlns:android="http://schemas.android.com/apk/res/android" 이외에 xmlns에 패키지 명을 넣어서 해보라는데

 

넣었더니 XML 에서 handle 과 content를 찾을 수 없다며 에러가 뜹니다.

 

<kr.co.lguplus.applauncher2.utils.SlideButton

     xmlns:slidedrawer="http://schemas.android.com/apk/res/kr.co.mypackage"

     android:id="@+id/slideOnOff"
     android:layout_gravity="right|center_vertical"

     slidedrawer:content="@+id/slideContentLayout"
     slidedrawer:handle="@+id/slideHandle"

 

애니메이션 속도하나 바꾸려니 정말 일이 커진듯합니다.

이번 작업을 마치면 다른 기본 Control 들도 소스를 가져다가 수정해서 자유롭게 쓸 수 있을거 같으데...

막히는 벽이 힘드네요...

 

잘  아시는 분들의 많은 도움 부탁드립니다.

 

감사합니다.