标签:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> <SlidingDrawer android:id="@+id/sd" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:handle="@+id/img" 设置把手 android:content="@+id/lin" 设置域 android:background="#fd8"> <ImageView android:id="@+id/img" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/star_full" /> <LinearLayout android:id="@+id/lin" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> </LinearLayout> </SlidingDrawer> </LinearLayout>
package com.example.sliding; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.SlidingDrawer; import android.widget.Toast; import android.widget.SlidingDrawer.OnDrawerCloseListener; import android.widget.SlidingDrawer.OnDrawerOpenListener; import android.widget.SlidingDrawer.OnDrawerScrollListener; public class MainActivity extends Activity { private ListView lv; private SlidingDrawer sd; private LinearLayout lin; private ImageView img; private String[] data = {"one","two","three"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); lv = new ListView(this); lv.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,data)); sd = (SlidingDrawer) findViewById(R.id.sd); lin = (LinearLayout) findViewById(R.id.lin); img = (ImageView) findViewById(R.id.img); lin.addView(lv); //窗口打开 sd.setOnDrawerOpenListener(new OnDrawerOpenListener() { @Override public void onDrawerOpened() { img.setImageResource(R.drawable.star_empty); } }); //窗口关闭 sd.setOnDrawerCloseListener(new OnDrawerCloseListener() { @Override public void onDrawerClosed() { // TODO Auto-generated method stub img.setImageResource(R.drawable.star_full); } }); sd.setOnDrawerScrollListener(new OnDrawerScrollListener() { @Override public void onScrollStarted() { // TODO Auto-generated method stub Toast.makeText(MainActivity.this, "滑动开始", 1000).show(); } @Override public void onScrollEnded() { // TODO Auto-generated method stub Toast.makeText(MainActivity.this, "滑动结束", 1000).show(); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
标签:
原文地址:http://www.cnblogs.com/84126858jmz/p/4901157.html