Custom slidingdrawer drawer effects and slidingdrawer drawer Effects

Source: Internet
Author: User

 

1. Custom s0000ingdrawer drawer Effect

 

Effect 1

 

 

Effect 2

Effect 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 = "button 1"/> <button Android: Id = "@ + ID/button2" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "button 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 Resources

 

 

2. slidingdrawer drawer Effect

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: Orien Tation = "vertical"> <! -- Note: Android: handle = "@ + ID/handle" is a handle android that can be dragged: content = "@ + ID/content" is a view that can hide content --> <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 {// here 50 rows are returned. The number of rows in listview depends on the getcount () method 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 tutorial" + position); mbookauthor. settext ("SS" + position); Return v ;}}}

 

Resource: http://download.csdn.net/detail/niejing654092427/4504039

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.