自定义SlidingDrawer抽屉式效果和SlidingDrawer抽屉式效果
来源:互联网 发布:淘宝客户信息购买 编辑:程序博客网 时间:2024/04/29 12:37
1.自定义的SlidingDrawer抽屉式效果
效果1
效果2
效果3
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.cn.npass.nj" 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:label="@string/app_name" android:name=".SlidingDrawerDemoActivity" > <intent-filter > <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application></manifest>
wrapsliding.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="@color/gainsboro" android:orientation="vertical" > <com.cn.npass.nj.WrapSlidingDrawer android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_alignParentRight="true" android:content="@+id/content" android:handle="@+id/handle" android:orientation="vertical" > <Button android:id="@+id/handle" android:layout_width="30dip" android:layout_height="30dip" android:background="@drawable/help" /> <LinearLayout android:id="@+id/content" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/peachpuff" android:orientation="horizontal" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按钮1" /><Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按钮2" /> </LinearLayout> </com.cn.npass.nj.WrapSlidingDrawer></RelativeLayout>
SlidingDrawerDemoActivity.java
package com.cn.npass.nj;import android.app.Activity;import android.os.Bundle;public class SlidingDrawerDemoActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.wrapsliding); }}
WrapSlidingDrawer.java
package com.cn.npass.nj;import android.content.Context;import android.util.AttributeSet;import android.view.View;import android.widget.SlidingDrawer;public class WrapSlidingDrawer extends SlidingDrawer { private boolean mVertical; private int mTopOffset; public WrapSlidingDrawer(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); int orientation = attrs.getAttributeIntValue("android", "orientation", ORIENTATION_VERTICAL); mTopOffset = attrs.getAttributeIntValue("android", "topOffset", 0); mVertical = (orientation == SlidingDrawer.ORIENTATION_VERTICAL); } public WrapSlidingDrawer(Context context, AttributeSet attrs) { super(context, attrs); int orientation = attrs.getAttributeIntValue("android", "orientation", ORIENTATION_VERTICAL); mTopOffset = attrs.getAttributeIntValue("android", "topOffset", 0); mVertical = (orientation == SlidingDrawer.ORIENTATION_VERTICAL); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec); int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec); int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec); int heightSpecSize = MeasureSpec.getSize(heightMeasureSpec); final View handle = getHandle(); final View content = getContent(); measureChild(handle, widthMeasureSpec, heightMeasureSpec); if (mVertical) { int height = heightSpecSize - handle.getMeasuredHeight() - mTopOffset; content.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(height, heightSpecMode)); heightSpecSize = handle.getMeasuredHeight() + mTopOffset + content.getMeasuredHeight(); widthSpecSize = content.getMeasuredWidth(); if (handle.getMeasuredWidth() > widthSpecSize) widthSpecSize = handle.getMeasuredWidth(); } else { int width = widthSpecSize - handle.getMeasuredWidth() - mTopOffset; getContent().measure(MeasureSpec.makeMeasureSpec(width, widthSpecMode), heightMeasureSpec); widthSpecSize = handle.getMeasuredWidth() + mTopOffset + content.getMeasuredWidth(); heightSpecSize = content.getMeasuredHeight(); if (handle.getMeasuredHeight() > heightSpecSize) heightSpecSize = handle.getMeasuredHeight(); } setMeasuredDimension(widthSpecSize, heightSpecSize); } }
资源下载地址:http://download.csdn.net/detail/niejing654092427/4498795
2.SlidingDrawer抽屉式效果
效果图1
效果图2
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.cn.npass" 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:label="@string/app_name" android:name=".MainActivity" > <intent-filter > <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application></manifest>
main.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:background="@drawable/bg"> <SlidingDrawer android:id="@+id/slidingdrawer" android:layout_width="fill_parent" android:layout_height="fill_parent" android:handle="@+id/handle" android:content="@+id/content" android:orientation="vertical" > <!-- 说明: android:handle="@+id/handle" 是可以拖动的handle android:content="@+id/content" 是可以隐藏内容的View --> <Button android:id="@+id/handle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/icon2" /> <ListView android:id="@+id/content" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </SlidingDrawer></LinearLayout>
listview_item.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffff" android:orientation="vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:padding="6px" > <TextView android:id="@+id/bookname" android:layout_width="fill_parent" android:layout_height="fill_parent" android:textColor="#000000" android:textSize="20px" /> <TextView android:id="@+id/author" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="#000000" android:textSize="16px" /> </LinearLayout></LinearLayout>
MainActivity.java
package com.cn.npass;import android.app.Activity;import android.os.Bundle;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.ListView;import android.widget.TextView;public class MainActivity extends Activity {private ListView mListView;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);setupViews();}private void setupViews() {mListView = (ListView) findViewById(R.id.content);mListView.setAdapter(new ListViewAdapter());}private class ListViewAdapter extends BaseAdapter {// 这里返回50行,ListView有多少行取决于getCount()方法public int getCount() {return 50;}public Object getItem(int arg0) {return null;}public long getItemId(int arg0) {return 0;}public View getView(int position, View v, ViewGroup parent) {final LayoutInflater inflater = LayoutInflater.from(getApplicationContext());if (v == null) {v = inflater.inflate(R.layout.listview_item, null);}TextView mBookName = (TextView) v.findViewById(R.id.bookname);TextView mBookAuthor = (TextView) v.findViewById(R.id.author);mBookName.setText("Android教程" + position);mBookAuthor.setText("ss" + position);return v;}}}
资源下载地址为: http://download.csdn.net/detail/niejing654092427/4504039
- 自定义SlidingDrawer抽屉式效果和SlidingDrawer抽屉式效果
- 用SlidingDrawer实现隐藏式抽屉效果
- Android Apps 滑动式抽屉(SlidingDrawer)效果
- 用SlidingDrawer实现隐藏式抽屉效果
- SlidingDrawer--抽屉效果
- SlidingDrawer 抽屉效果
- SlidingDrawer 抽屉效果
- 自定义SlidingDrawer抽屉式效果(自定义slidingdrawer,使他只能拖拽无法点击)
- Android之SlidingDrawer抽屉效果
- Android SlidingDrawer 滑动抽屉效果
- Android之SlidingDrawer抽屉效果
- android 抽屉效果 (SlidingDrawer)
- 用SlidingDrawer实现抽屉效果
- 滑动式抽屉(SlidingDrawer)
- iOS 自定义抽屉式效果--ViewDeck(SlidingDrawer)实现与使用详解
- Android之抽屉效果(自定义、GridView、SlidingDrawer结合)案例
- 自定义四个方向上的SlidingDrawer(抽屉效果)
- 自定义四个方向上的SlidingDrawer(抽屉效果)
- u-boot_smdkv210 分析二:启动代码start.s分析
- Extjs-Flash报表 柱状栈图
- Android开发:Framework添加新模块
- u-boot_smdkv210 分析三:启动代码lowlevel.s分析
- DIV+CSS实现区域鼠标事件的动态效果
- 自定义SlidingDrawer抽屉式效果和SlidingDrawer抽屉式效果
- u-boot_smdkv210 分析四:启动代码汇编部分总结
- hdu1077已知半径以及圆上2点求圆心 圆圈点的个数
- UITextField 输入英文会出现EXC_BAD_ACCESS错误的
- u-boot_smdkv210 分析六:内存分配
- Connections could not be acquired from the underlying database!原因及解决办法
- ServletContext(不同用户在服务器端共享数据)
- u-boot_smdkv210 分析五:硬件启动过程
- [转] 栈的内存管理