抽屜組件的滑動效果

佈局文件:

<SlidingDrawer
android:id="@+id/slidingdrawer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:content="@+id/content"
android:handle="@+id/handle"
android:orientation="horizontal" >

<ImageView
android:id="@+id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ico_left" />
<LinearLayout
android:id="@+id/content"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:background="#f00"
android:orientation="vertical" >
</LinearLayout>
</SlidingDrawer>

 

代碼示例演示:

layout.addView(this.listView); // 增長組件
this.slidingDrawer = (SlidingDrawer) super.findViewById(R.id.slidingdrawer);
this.handle = (ImageView) super.findViewById(R.id.handle);// 取得組件
this.slidingDrawer.setOnDrawerOpenListener( new OnDrawerOpenListenerImpl()); // 設置監聽
this.slidingDrawer.setOnDrawerCloseListener(new OnDrawerCloseListenerImpl()); // 設置監聽
this.slidingDrawer.setOnDrawerScrollListener(new OnDrawerScrollListenerImpl());// 設置監聽
}

private class OnDrawerOpenListenerImpl implements OnDrawerOpenListener {
@Override
public void onDrawerOpened() {
handle.setImageResource(R.drawable.ico_right); // 窗口打開監聽
}
}

private class OnDrawerCloseListenerImpl implements OnDrawerCloseListener {
@Override
public void onDrawerClosed() {
handle.setImageResource(R.drawable.ico_left); // 窗口關閉監聽
}
}

private class OnDrawerScrollListenerImpl implements OnDrawerScrollListener {
@Override
public void onScrollEnded() { // 拖動結束
Toast.makeText(Tabone_music.this, "窗口拖動結束。", Toast.LENGTH_SHORT).show();
}

@Override
public void onScrollStarted() { // 拖動開始
Toast.makeText(Tabone_music.this, "正在拖動窗口。", Toast.LENGTH_SHORT).show();
}
}

 

聲明的變量名:

private String data[] = { "音樂電臺", "個人收藏", "用戶設置", "個人資料", "音樂論壇" }; // 定義顯示的數據
private ListView listView; // 定義ListView組件
private SlidingDrawer slidingDrawer; // 定義SlidingDrawer

 

 

 
相關文章
相關標籤/搜索