classSlider

Last-modified: 2015-03-18 (水) 12:29:57
public class Slider extends Activity implements OnClickListener, OnCheckedChangeListener, OnDrawerOpenListener{

	SlidingDrawer sd;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO 自動生成されたメソッド・スタブ
		super.onCreate(savedInstanceState);
		setContentView(R.layout.sliding);
		Button handle1 = (Button) findViewById(R.id.handle1);
		Button handle2 = (Button) findViewById(R.id.handle2);
		Button handle3 = (Button) findViewById(R.id.handle3);
		Button handle4 = (Button) findViewById(R.id.handle4);
		CheckBox checkbox = (CheckBox) findViewById(R.id.cbSlidaable);
		sd = (SlidingDrawer) findViewById(R.id.slidingD);

		checkbox.setOnCheckedChangeListener(this);
		sd.setOnDrawerOpenListener(this);

		handle1.setOnClickListener(this);
		handle2.setOnClickListener(this);
		handle3.setOnClickListener(this);
		handle4.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		// TODO 自動生成されたメソッド・スタブ
		switch(v.getId()){
		case R.id.handle1: sd.open(); break;
		case R.id.handle2: break;
		case R.id.handle3: sd.toggle(); break;
		case R.id.handle4: sd.close(); break;
		}
	}

	@Override
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		// TODO 自動生成されたメソッド・スタブ
		if(buttonView.isChecked()){
			sd.lock();
		} else {
			sd.unlock();
		}
	}

	@Override
	public void onDrawerOpened() {
		// TODO 自動生成されたメソッド・スタブ
		MediaPlayer mp = MediaPlayer.create(this, R.raw.explosion);
		mp.start();
	}
}
~~~




~<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
~<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <Button android:id="@+id/handle1" android:text="Handle" android:layout_width="wrap_content" android:layout_height="wrap_content" />
    <Button android:id="@+id/handle2" android:text="Handle" android:layout_width="wrap_content" android:layout_height="wrap_content" />
    <Button android:id="@+id/handle3" android:text="Handle" android:layout_width="wrap_content" android:layout_height="wrap_content" />
    <Button android:id="@+id/handle4" android:text="Handle" android:layout_width="wrap_content" android:layout_height="wrap_content" />
~</LinearLayout>
    <SlidingDrawer
        android:id="@+id/slidingD"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:content="@+id/content"
        android:handle="@+id/handle" >
        <Button
            android:id="@+id/handle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Handle" />
        <LinearLayout
            android:id="@+id/content"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
              <CheckBox
		        android:id="@+id/cbSlidaable"
		        android:layout_width="wrap_content"
		        android:layout_height="wrap_content"
		        android:text="CheckBox" />
        </LinearLayout>
    </SlidingDrawer>
~</FrameLayout>