淘宝(阿里百川)手机客户端开发日记第三篇 SlidingPaneLayout实现侧滑菜单
需要的三个布局文件:
activity_main.xml :主窗体布局
left.xml : 左侧栏目分类布局
right.xml : 右侧内容详情
需要的组件: android.support.v4.widget.SlidingPaneLayout
布局代码
activity_main.xml
<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"
tools:context="com.example.slidepaneldemo.MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="分类" />
</LinearLayout>
<View android:layout_width="match_parent"
android:layout_height="0.6dp"
android:background="#ff0000"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.v4.widget.SlidingPaneLayout
android:id="@+id/slidepanel"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<include
android:id="@+id/id_left"
layout="@layout/left"/>
<include
android:id="@+id/id_left"
layout="@layout/right"/>
</android.support.v4.widget.SlidingPaneLayout>
</LinearLayout>
</LinearLayout>
其中:left.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="92dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#cccccc">
<ListView
android:layout_width="92dp"
android:layout_height="match_parent"
android:entries="@array/menu_list" >
</ListView>
</LinearLayout>
right.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="173dp"
android:text="右侧正文" />
</RelativeLayout>
对应的图示效果:左侧图,右侧图 ,主窗体图(第三张图和第二张图差不多,但是第三张图示主窗体图,其中,左侧图默认不显示。)



我们现在需要实现点击分类,将左侧的分类展现出来,如图效果:

实现代码如下(.java):
package com.example.slidepaneldemo;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.widget.SlidingPaneLayout;
import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity implements PanelSlideListener {
Button button1;
SlidingPaneLayout slidepanel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button1 = (Button)findViewById(R.id.button1);
slidepanel = (SlidingPaneLayout)findViewById(R.id.slidepanel);
/* * 判断左侧分类是否展示,很简单的逻辑代码吧 */
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if(!slidepanel.isOpen())
{
slidepanel.openPane();
}
else
{
slidepanel.closePane();
}
}
});
}
@Override
public void onPanelClosed(View arg0) {
// TODO Auto-generated method stub
}
@Override
public void onPanelOpened(View arg0) {
// TODO Auto-generated method stub
}
@Override
public void onPanelSlide(View arg0, float arg1) {
// TODO Auto-generated method stub
}
}
转载请注明http://www.cnblogs.com/yushengbo,否则将追究版权责任!
淘宝(阿里百川)手机客户端开发日记第三篇 SlidingPaneLayout实现侧滑菜单的更多相关文章
- 淘宝(阿里百川)手机客户端开发日记第十一篇 JSP+Servlet
由于本人从事.net开发已有多年经验,今天由于工作需要,我只能学习下JSP+Servlet,至于java web提供了更好的开发框架MVC,现在由于时间关系,我只好用JSP+Servlet来搭建服务器 ...
- 淘宝(阿里百川)手机客户端开发日记第五篇 SharedPreferences使用详解
我们知道,Android中数据存储技术由于如下几种 1 使用SharedPreferences存储数据 2 文件存储数据 3 SQLite数据库存储数据 4 使用ContentProvider存储数据 ...
- 淘宝(阿里百川)手机客户端开发日记第十篇 阿里百川服务器环境介绍之API文档的快速链接(四)
个人感觉比较重要的快速链接: http://open.taobao.com/doc/detail.htm?id=102513 http://open.taobao.com/doc/detail.htm ...
- 淘宝(阿里百川)手机客户端开发日记第十三篇 mysql的连接
首先,我建立了一个包,里面存放了三个类文件,这三个文件是我从网络中找的,经过自己的整理.(我刚才查找想把这三个文件传上去,可能是自己对cnblogs的博客不太熟悉吧,没有找到,我只好粘贴代码了) 三个 ...
- 淘宝(阿里百川)手机客户端开发日记第八篇 Handler的使用方法
首先,我们先看下API文档的说明: A Handler allows you to send and process Message and Runnable objects associated w ...
- 淘宝(阿里百川)手机客户端开发日记第七篇 Service,Handler和Thread
现在我们已经已经知道android有Service,Handler和Thread这些内容了,但是我想应该还有很多人对此并不是很清楚他们之间的区别! (1)Service 是运行在后端的程序,不与UI直 ...
- 淘宝(阿里百川)手机客户端开发日记第六篇 Service详解(六)
Service和Thread的关系 不少初学者都可能会有这样的疑惑,Service和Thread到底有什么关系呢?什么时候应该用Service,什么时候又应该用Thread? 答案是Service和T ...
- 淘宝(阿里百川)手机客户端开发日记第六篇 Service详解(五)
我们现在对上一节中的DEMO进行改进,在服务中开启线程来执行. package com.example.service; import android.app.Service; import andr ...
- 淘宝(阿里百川)手机客户端开发日记第六篇 Service详解(四)
DEMO1:在Activity里声明一个回调方法,当service完成任务后,调用这个回调方法. 首先,我们先继承service,来创建服务,代码如下: package com.example.ser ...
随机推荐
- php模式设计之 工厂模式
承接上篇php模式设计之 单例模式,(虽然好像关系不大).今天讲述第二种基础的模式设计——工厂模式. 那么何为工厂模式? 从名字来看,似乎看不出什么端倪.工厂模式,和生产有关?还是和生产流程有关?难道 ...
- [USACO2002][poj1944]Fiber Communications(枚举)
Fiber Communications Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3804 Accepted: 1 ...
- jQuery理解之(二)功能函数
在javascript编程中,开发者通常需要编写很多小程序来实现一些特定的功能.例如浏览器检测,字符串处理.数组的编辑等.jQuery对这些常用的程序进行了总结,提供了很多实用的函数. 1.检测浏览器 ...
- C基础--结构体
C语言,结构体语法: 1.定义结构体类型: struct 结构体名称 { 成员类型 成员名称1; 成员类型 成员名称2; ... }; 例:struct Date { int year ; int m ...
- js 选项卡实现
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8&quo ...
- 使用TransactionScopeOption 管理事务流
可通过调用一个方法来嵌套事务范围,该方法在使用其自己范围的方法中使用 TransactionScope,下面示例中的 RootMethod 方法就是前者这样的方法. void RootMethod() ...
- javascript 规范
关于变量及方法等的命名,没有硬性规定,但是为了规范,遵循一些约定还是有必要的. 变量定义: 用var 关键字将要使用的变量定义在代码开头,变量间用分号隔开. 原因有二: 一是便于理解,知道下面的代码会 ...
- 17.(转) Android之四大基本组件介绍与生命周期
Android四大基本组件分别是Activity,Service服务,Content Provider内容提供者,BroadcastReceiver广播接收器. 一:了解四大基本组件 Activity ...
- 两个大的整数的运算(java)
import java.math.BigInteger; public class BigInt { BigInteger m1; BigInteger m2; BigInteger m3; BigI ...
- AndroidManifest File Features
http://www.android-doc.com/guide/topics/manifest/manifest-intro.html The following sections describe ...