Im trying to change the icon on the handle when i try to open the slidingdrawer. When I extract the handle from the view and sets the onclicklistener or ontouchlistener it seems to never get trigget.
我试图打开滑动抽屉时试图改变手柄上的图标。当我从视图中提取句柄并设置onclicklistener或ontouchlistener时,似乎永远不会获得trigget。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SlidingDrawer drawer = (SlidingDrawer)findViewById(R.id.drawer_landscape);
ImageView handle = (ImageView)findViewById(R.id.handle_l);
handle.setFocusable(true);
handle.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.i("test","onClick");
}
});
}
And my XML
还有我的XML
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/base_frame_layout"
android:layout_gravity="bottom"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>
<SlidingDrawer
android:id="@+id/drawer_landscape"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:handle="@+id/handle_l"
android:content="@+id/content"
android:orientation="vertical"
android:visibility="visible"
>
<ImageView
android:id="@+id/handle_l"
android:layout_height="50px"
android:layout_width="64px"
android:padding="0px"
android:src="@drawable/icon"
/>
<TextView
android:id="@+id/content"
android:text="content"
android:layout_height="50px"
android:layout_width="64px"
/>
</SlidingDrawer>
</FrameLayout>
I was hoping this code should log "onClick" message, but it doesn't.
我希望这段代码应该记录“onClick”消息,但事实并非如此。
Any ideas?
2 个解决方案
#1
I found it, it was pritty easy... I just need to setOnDrawerScrollListener on my drawer.
我发现它很简单......我只需要在抽屉上设置setOnDrawerScrollListener。
than implement the 2 methods onScrollEnded and onScrollStarted.
而不是实现onScrollEnded和onScrollStarted上的2个方法。
mSlidingDrawer.setOnDrawerScrollListener(new OnDrawerScrollListener(){
@Override
public void onScrollEnded() {
// TODO Auto-generated method stub
Log.i("ddd","onScrollEnded slider");
slider_animation.reverseTransition(HANDLE_ANIMATION_SPEED);
}
@Override
public void onScrollStarted() {
// TODO Auto-generated method stub
Log.i("ddd","onScrollStarted slider");
slider_animation.startTransition(HANDLE_ANIMATION_SPEED);
}
});
I rather use an animation on the handle instead of changing the Image bacause of the flickering.
我宁愿在手柄上使用动画而不是改变图像因为闪烁。
#2
I found it for along time , but now it is completed about it . It is the best way for Change Image Handle when you click to view SlidingDrawer.
我一直找到它,但现在它已经完成了。当您单击以查看SlidingDrawer时,这是更改图像处理的最佳方式。
It have 2 Method that we use in code below.
我们在下面的代码中使用了2个方法。
final SlidingDrawer drawer = (SlidingDrawer)findViewById(R.id.slidingDrawer);
drawer.setOnDrawerOpenListener(new SlidingDrawer.OnDrawerOpenListener() {
@Override
public void onDrawerOpened() {
arr.setImageResource(R.drawable.arrowdown);
}
});
drawer.setOnDrawerCloseListener(new SlidingDrawer.OnDrawerCloseListener() {
@Override
public void onDrawerClosed() {
arr.setImageResource(R.drawable.arrowup);
}
});
#1
I found it, it was pritty easy... I just need to setOnDrawerScrollListener on my drawer.
我发现它很简单......我只需要在抽屉上设置setOnDrawerScrollListener。
than implement the 2 methods onScrollEnded and onScrollStarted.
而不是实现onScrollEnded和onScrollStarted上的2个方法。
mSlidingDrawer.setOnDrawerScrollListener(new OnDrawerScrollListener(){
@Override
public void onScrollEnded() {
// TODO Auto-generated method stub
Log.i("ddd","onScrollEnded slider");
slider_animation.reverseTransition(HANDLE_ANIMATION_SPEED);
}
@Override
public void onScrollStarted() {
// TODO Auto-generated method stub
Log.i("ddd","onScrollStarted slider");
slider_animation.startTransition(HANDLE_ANIMATION_SPEED);
}
});
I rather use an animation on the handle instead of changing the Image bacause of the flickering.
我宁愿在手柄上使用动画而不是改变图像因为闪烁。
#2
I found it for along time , but now it is completed about it . It is the best way for Change Image Handle when you click to view SlidingDrawer.
我一直找到它,但现在它已经完成了。当您单击以查看SlidingDrawer时,这是更改图像处理的最佳方式。
It have 2 Method that we use in code below.
我们在下面的代码中使用了2个方法。
final SlidingDrawer drawer = (SlidingDrawer)findViewById(R.id.slidingDrawer);
drawer.setOnDrawerOpenListener(new SlidingDrawer.OnDrawerOpenListener() {
@Override
public void onDrawerOpened() {
arr.setImageResource(R.drawable.arrowdown);
}
});
drawer.setOnDrawerCloseListener(new SlidingDrawer.OnDrawerCloseListener() {
@Override
public void onDrawerClosed() {
arr.setImageResource(R.drawable.arrowup);
}
});