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:java
<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/7229200android
而後我寫的layout以下:app
<?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代碼以下 :ide
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); } }); } }
大概就是上面 的了。哈哈。 ui
上面內容參考:http://my.oschina.net/chen106106/blog/49041this
2. 上面的一個重大的問題就是,默認不是上向下拉的。而android的狀態欄默認是從上向下拉的。google
你用中文搜索的時候發現得最多的解決方案是:使用Panelspa
這個類的地址在:.net
介紹的文章我看到最初來自: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/