用SlidingDrawer实现类似android状态栏下拉上拉效果!

首先看下android 的API

Class Overview

SlidingDrawer hides content out of the screen and allows the user to drag a handle to bring the content on screen. SlidingDrawer can be used vertically or horizontally. A special widget composed of two children views: the handle, that the users drags, and the content, attached to the handle and dragged with it. SlidingDrawer should be used as an overlay inside layouts. This means SlidingDrawer should only be used inside of a FrameLayout or a RelativeLayout for instance. The size of the SlidingDrawer defines how much space the content will occupy once slid out so SlidingDrawer should usually use match_parent for both its dimensions. Inside an XML layout, SlidingDrawer must define the id of the handle and of the content:

 <SlidingDrawer      
android:id="@+id/drawer"      
android:layout_width="match_parent"      android:layout_height="match_parent"      
android:handle="@+id/handle"      
android:content="@+id/content">     
 <ImageView          
android:id="@id/handle"         
 android:layout_width="88dip"         
 android:layout_height="44dip" />     
 <GridView         
 android:id="@id/content"         
 android:layout_width="match_parent"          android:layout_height="match_parent" /> 
 </SlidingDrawer>  

以下部分内容参考来自:http://blog.csdn.net/wangkuifeng0118/article/details/7229200

然后我写的layout如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <SlidingDrawer 
        android:id="@+id/slidingdraw"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:handle="@+id/handle"
        android:content="@+id/content"
        >
        <ListView 
            android:id="@id/content"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            />
               <ImageView android:id="@id/handle"
            android:src="@drawable/drawer_open"
            android:layout_width="88dip"
            android:layout_height="44dip" 
            android:contentDescription="TODO"/>
    </SlidingDrawer>

</LinearLayout>

整个Activity代码如下 :

package ditouch.client.guilin;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.SlidingDrawer;

public class SlidingDrawerActivity extends Activity {

	private SlidingDrawer mDrawer;
	private ImageView mImageView;
	private ListView mListView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.slidedraw_test);

		mDrawer = (SlidingDrawer) findViewById(R.id.slidingdraw);
		mImageView = (ImageView) findViewById(R.id.handle);
		mListView = (ListView) findViewById(R.id.content);

		String[] ids = { "1", "2", "3" };
		String[] titles = { "a", "b", "c" };
		List<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
		;
		HashMap<String, Object> map = new HashMap<String, Object>();
		for (int i = 0; i < ids.length; i++) {
			map.put("ids", ids[i]);
			map.put("title", titles[i]);
			list.add(map);
		}
		SimpleAdapter adapter = new SimpleAdapter(this, list,
				R.layout.ordered_item, new String[] { "ids", "title" },
				new int[] { R.id.ids, R.id.title });
		mListView.setAdapter(adapter);

		mDrawer.setOnDrawerOpenListener(new SlidingDrawer.OnDrawerOpenListener() {
			@Override
			public void onDrawerOpened() {
				mImageView.setImageResource(R.drawable.drawer_close);
			}
		});
		mDrawer.setOnDrawerCloseListener(new SlidingDrawer.OnDrawerCloseListener() {
			@Override
			public void onDrawerClosed() {
				mImageView.setImageResource(R.drawable.drawer_open);
			}
		});
		

	}

}

大概就是上面 的了。哈哈。

上面内容参考:http://my.oschina.net/chen106106/blog/49041

 

2. 上面的一个重大的问题就是,默认不是上向下拉的。而android的状态栏默认是从上向下拉的。

  你用中文搜索的时候发现得最多的解决方案是:使用Panel

这个类的地址在:

http://code.google.com/p/android-misc-widgets/source/browse/trunk/android-misc-widgets/src/org/miscwidgets/widget/Panel.java

介绍的文章我看到最初来自:http://blog.csdn.net/hellogv/article/details/6789698

然后使用这个类我是我想要的,然后就用英文搜索:Slidingdrawer drop from top  to bottom

第一条根据android的SlidingDrawer改写widget。哈哈,就是我想要的。

http://blog.sephiroth.it/2011/03/29/widget-slidingdrawer-top-to-bottom/

 

 



你可能感兴趣的:(android,slidingdrawer,下拉,上拉)