• SlidingDrawer的简单实例(抽屉效果)


    main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/white" >

    <SlidingDrawer
    android:id="@+id/SlidingDrawer"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:content="@+id/content"
    android:handle="@+id/layout1" >

    <LinearLayout
    android:id="@+id/layout1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center" >

    <ImageView
    android:id="@+id/handle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="bb"
    android:src="@drawable/taskup" />
    </LinearLayout>

    <ImageView
    android:id="@+id/content"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:contentDescription="ccc"
    android:src="@drawable/test" />
    </SlidingDrawer>

    <GridView
    android:id="@+id/gridview"
    android:layout_below="@+id/SlidingDrawer"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:columnWidth="50dip"
    android:gravity="center"
    android:horizontalSpacing="10dip"
    android:numColumns="auto_fit"
    android:verticalSpacing="10dp" />

    </RelativeLayout>

    item.xml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="4dip" >

    <ImageView
    android:id="@+id/ItemImage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >
    </ImageView>

    <TextView
    android:id="@+id/ItemText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/ItemImage"
    android:text="TextView01" >
    </TextView>

    </RelativeLayout>

    ChoutiActivity.xml

    package com.wu.test;

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

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

    public class ChoutiActivity extends Activity {

    private ImageView iv = null;
    private ImageView ivdown = null;
    private SlidingDrawer sg = null;
    private GridView gridView = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    initWidget(); // 初始化组件
    sg.animateOpen(); // 默认打开
    fillGridView();
    registerListener(); // 组件事件注册
    }

    private void initWidget(){
    iv = (ImageView) findViewById(R.id.content);
    ivdown = (ImageView) findViewById(R.id.handle);
    sg = (SlidingDrawer) findViewById(R.id.SlidingDrawer);
    gridView = (GridView) findViewById(R.id.gridview);
    }

    /**
    * 往GridView填充测试数据
    */
    private void fillGridView(){
    ArrayList<HashMap<String, Object>> lstImageItem = new ArrayList<HashMap<String, Object>>();
    for (int i = 0; i < 10; i++) {
    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put("ItemImage", R.drawable.ic_launcher);
    map.put("ItemText", "NO." + String.valueOf(i));
    lstImageItem.add(map);
    }

    SimpleAdapter saImageItems = new SimpleAdapter(this, lstImageItem,
    R.layout.item, new String[] { "ItemImage", "ItemText" },
    new int[] { R.id.ItemImage, R.id.ItemText });
    gridView.setAdapter(saImageItems);
    }

    private void registerListener(){
    sg.setOnDrawerOpenListener(new drawOpenListener());//打开
    sg.setOnDrawerCloseListener(new drawCloseListener());//关闭
    sg.setOnDrawerScrollListener(new drawScrollListener());//滑动
    }

    class drawOpenListener implements OnDrawerOpenListener{

    @Override
    public void onDrawerOpened() {
    ivdown.setImageResource(R.drawable.down);
    }

    }

    class drawCloseListener implements OnDrawerCloseListener{

    @Override
    public void onDrawerClosed() {
    ivdown.setImageResource(R.drawable.taskup);
    }

    }

    class drawScrollListener implements OnDrawerScrollListener{

    @Override
    public void onScrollEnded() {
    //Toast.makeText(getApplicationContext(),"33333333333333333",Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onScrollStarted() {

    }

    }

    @Override
    protected void onResume() {
    super.onResume();
    }

    }

  • 相关阅读:
    Mysql的左外连接丶右外连接与内连接的区别
    常见的异常种类
    Mysql
    JSTL 标签库
    VMware的虚拟机为什么ip地址老是自动变化?
    redis出现的问题
    在Linux系统下启动了tomcat,但是在游览器中进步了服务
    Linux下安装JDK 与 tomcat
    wamp配置多站点域名
    终端链接操作redis
  • 原文地址:https://www.cnblogs.com/xingmeng/p/2544670.html
Copyright © 2020-2023  润新知