为什么会有错呢? 代码没错啊。是不是manifest 有错。。?

每周精粹 发布于 2012/06/07 17:57
阅读 92
收藏 0
package com.drawer.demo;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.SlidingDrawer;
import android.widget.SlidingDrawer.OnDrawerCloseListener;
import android.widget.SlidingDrawer.OnDrawerOpenListener;
import android.widget.SlidingDrawer.OnDrawerScrollListener;
import android.widget.TextView;

public class DrawerActivity extends Activity {
    /** Called when the activity is first created. */
   
   
    private ImageView img;
    private SlidingDrawer sliding;
    private TextView txt;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        img=(ImageView)findViewById(R.id.handle);
        sliding=(SlidingDrawer)findViewById(R.id.content);
        txt=(TextView)findViewById(R.id.txt);
        sliding.setOnDrawerOpenListener(new OnDrawerOpenListener(){

            @Override
            public void onDrawerOpened() {
                // TODO Auto-generated method stub
                img.setImageResource(R.drawable.dawn);
            }});
        sliding.setOnDrawerCloseListener(new OnDrawerCloseListener(){

            @Override
            public void onDrawerClosed() {
                // TODO Auto-generated method stub
                img.setImageResource(R.drawable.up);
            }});
       
        sliding.setOnDrawerScrollListener(new OnDrawerScrollListener(){

            @Override
            public void onScrollEnded() {
                // TODO Auto-generated method stub
                txt.setText(R.string.app_name);
            }

            @Override
            public void onScrollStarted() {
                // TODO Auto-generated method stub
                txt.setText(R.string.hello);
            }});
       
    }

}

 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.drawer.demo"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".DrawerActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

 

<?xml version="1.0" encoding="utf-8"?>
<SlidingDrawer xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
     android:orientation="vertical"
     android:id="@+id/handle"
    android:content="@+id/content">
    <ImageView
        android:id="@id/handle"
        android:layout_width="50dip"
        android:layout_height="40dip"
        android:src="@drawable/up"
        android:contentDescription="@string/hello"
        />
    <LinearLayout
        android:id="@id/content"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#686868"
        >
        <TextView
            android:id="@+id/txt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/hello"/>                                               
    </LinearLayout>      
</SlidingDrawer>
   

 

 

加载中
返回顶部
顶部