Android drawer Activity (used by Renren ))

Source: Internet
Author: User


 

--------------------------- Main. xml

<? Xml version = "1.0" encoding = "UTF-8"?>
<AbsoluteLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: id = "@ + id/layout"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">
 
<FrameLayout
Android: id = "@ + id/slideout_placeholder"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: background = "#777777">
 
<ListView
Android: id = "@ + id/list"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: cacheColorHint = "#00000000" type = "codeph" text = "/codeph"/>
</FrameLayout>
 
<ImageView
Android: id = "@ + id/slidedout_cover"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: scaleType = "fitXY"/>
 
</AbsoluteLayout>


------------------------ Blog. xml

<? Xml version = "1.0" encoding = "UTF-8"?>
<RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: id = "@ + id/inner_content"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: background = "@ android: color/white">

<LinearLayout
Android: id = "@ + id/linearLayout1"
Android: layout_width = "fill_parent"
Android: layout_height = "45dip"
Android: background = "# bb000000"
Android: gravity = "center_vertical"
Android: orientation = "horizontal">

<Button
Android: id = "@ + id/sample_button"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_marginRight = "10dip"
Android: background = "@ drawable/right"/>

<TextView
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "I hate working plain white"
Android: textColor = "# ffffff"
Android: textSize = "19sp"/>
</LinearLayout>

<WebView
Xmlns: android = "http://schemas.android.com/apk/res/android"
Android: id = "@ + id/webView1"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: layout_marginTop = "40dip"/>

</RelativeLayout>

 

 

------------------------------. Main JAVA

Package slidh. co. cc;

Import android. app. Activity;
Import android. content. Context;
Import android. content. Intent;
Import android. graphics. Bitmap;
Import android. graphics. Bitmap. Config;
Import android. graphics. Canvas;
Import android. OS. Bundle;
Import android. util. TypedValue;
Import android. view. KeyEvent;
Import android. view. View;
Import android. view. View. OnClickListener;
Import android. view. WindowManager;
Import android. view. animation. Animation;
Import android. view. animation. Animation. AnimationListener;
Import android. view. animation. TranslateAnimation;
Import android. widget. AdapterView;
Import android. widget. AdapterView. OnItemClickListener;
Import android. widget. ArrayAdapter;
Import android. widget. ImageView;
Import android. widget. ListView;
Import android. widget. RelativeLayout. LayoutParams;

Public class SettingActivity extends
Activity {

Private ImageView mCover;
Private ListView mList;
Private Animation mStartAnimation;
Private Animation mStopAnimation;
Private static final int DURATION_MS = 400;
Private static Bitmap sCoverBitmap = null;
String loveyouString [] = new String [] {
"White studio", "handsome guy, handsome guy ",
"Handsome guy", "Beautiful Girl", "handsome guy ",
"Handsome guy handsome guy", "handsome guy ",
"Smile on the ground "};

// Two steps
// 1. activity --> other activity
// 2. anim
// Switch to another activity first
// Obtain the snapshot of the previous activity screen and overwrite it to the next screen as a cover. Then, the cover is moved through an animation, which makes it feel like moving the previous screen.

Public static void prepare (
Activity activity, int id ){
If (sCoverBitmap! = Null ){
SCoverBitmap. recycle ();
}
// Generate a transparent 32-Bit Bitmap with the specified size and use it to build a canvas
SCoverBitmap = Bitmap
. CreateBitmap (
Activity. findViewById (
Id)
. GetWidth (),
Activity. findViewById (
Id)
. GetHeight (),
Config. ARGB_8888 );
Canvas canvas = new Canvas (
SCoverBitmap );
// Render the specified view, including its subview, to the canvas. This is a snapshot of the previous activity layout. Now, this bitmap is the snapshot of the previous activity.
Activity. findViewById (id). draw (
Canvas );
}

@ Override
Public void onCreate (
Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
// The absolute layout overwrites an imageview.
SetContentView (R. layout. main );
InitAnim ();
MCover = (ImageView) findViewById (R. id. slidedout_cover );
MCover. setImageBitmap (sCoverBitmap );
MCover. setOnClickListener (new OnClickListener (){
@ Override
Public void onClick (View v ){
Close ();
}
});
MList = (ListView) findViewById (R. id. list );
MList. setAdapter (new ArrayAdapter <String> (
SettingActivity. this,
Android. R. layout. simple_list_item_1,
LoveyouString ));
MList. setOnItemClickListener (new OnItemClickListener (){

@ Override
Public void onItemClick (
AdapterView <?> Arg0,
View arg1,
Int arg2, long arg3 ){
// If (String [0]) {
//
//}
//
If (arg2 = 1 ){
Intent intent = new Intent (
SettingActivity. this,
Gongzibai. class );
StartActivity (intent );
Finish ();

}

If (arg2 = 3 ){

Intent intent1 = new Intent (
SettingActivity. this,
Gongzibai1.class );
StartActivity (intent1 );
Finish ();

}
Close ();

}
});
Open ();
}

Public void initAnim (){

// Adopts the absolute layout. The absolute layout starts from (0, 0) in the upper left corner of the view.
@ SuppressWarnings ("deprecation ")
Final android. widget. AbsoluteLayout. LayoutParams lp = new android. widget. AbsoluteLayout. LayoutParams (
LayoutParams. FILL_PARENT,
LayoutParams. FILL_PARENT,
0, 0 );
FindViewById (
R. id. slideout_placeholder)
. SetLayoutParams (lp );

// Screen width
Int displayWidth = (WindowManager) getSystemService (Context. WINDOW_SERVICE ))
. Getdefadisplay display ()
. GetWidth ();
// The right displacement, 60dp converted to px
Int sWidth = (int) TypedValue
. ApplyDimension (
TypedValue. COMPLEX_UNIT_DIP,
60,
GetResources ()
. GetDisplayMetrics ());
// Offset for moving the snapshot to the right
Final int shift = displayWidth
-SWidth;

// The shift animation moves to the right, and the shift distance to the right remains unchanged in the y direction.
MStartAnimation = new TranslateAnimation (
TranslateAnimation. ABSOLUTE,
0,
TranslateAnimation. ABSOLUTE,
Shift,
TranslateAnimation. ABSOLUTE,
0,
TranslateAnimation. ABSOLUTE,
0 );

// Displacement animation during rollback
MStopAnimation = new TranslateAnimation (
TranslateAnimation. ABSOLUTE,
0,
TranslateAnimation. ABSOLUTE,
-Shift,
TranslateAnimation. ABSOLUTE,
0,
TranslateAnimation. ABSOLUTE,
0 );
// Duration
MStartAnimation
. SetDuration (DURATION_MS );
// The animation stops at the end of the animation.
MStartAnimation
. SetFillAfter (true );
MStartAnimation
. SetAnimationListener (new AnimationListener (){

@ Override
Public void onAnimationStart (
Animation animation ){
}

@ Override
Public void onAnimationRepeat (
Animation animation ){
}

@ Override
Public void onAnimationEnd (
Animation animation ){
// Callback when the animation ends
// Fix the imageview to the position after the displacement
MCover. setAnimation (null );
@ SuppressWarnings ("deprecation ")
Final android. widget. AbsoluteLayout. LayoutParams lp = new android. widget. AbsoluteLayout. LayoutParams (
LayoutParams. FILL_PARENT,
LayoutParams. FILL_PARENT,
Shift,
0 );
MCover. setLayoutParams (lp );
}
});

MStopAnimation
. SetDuration (DURATION_MS );
MStopAnimation
. SetFillAfter (true );
MStopAnimation
. SetAnimationListener (new AnimationListener (){

@ Override
Public void onAnimationStart (
Animation animation ){
}

@ Override
Public void onAnimationRepeat (
Animation animation ){
}

@ Override
Public void onAnimationEnd (
Animation animation ){
Finish ();
OverridePendingTransition (
0, 0 );
}
});

}

Public void open (){
MCover. startAnimation (mStartAnimation );
}

Public void close (){
MCover. startAnimation (mStopAnimation );
}

@ Override
Public boolean onKeyDown (
Int keyCode, KeyEvent event ){
// The animation must be triggered when the return key is pressed.
If (keyCode = KeyEvent. KEYCODE_BACK ){
Close ();
Return true;
}
Return super. onKeyDown (keyCode,
Event );
}
}


----------------------- Project. avti.pdf

Package slidh. co. cc;

Import cn. mapplayer. engine. MiidiCredit;
Import android. app. Activity;
Import android. content. Intent;
Import android. OS. Bundle;
Import android. view. View;
Import android. view. View. OnClickListener;

Public class SliderActivity extends
Activity {
@ Override
Protected void onCreate (
Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );

 
SetContentView (R. layout. sample );
FindViewById (R. id. sample_button)
. SetOnClickListener (
New OnClickListener (){
@ Override
Public void onClick (
View v ){
SettingActivity
. Prepare (
SliderActivity. this,
R. id. inner_content );
StartActivity (new Intent (
SliderActivity. this,
SettingActivity. class ));
OverridePendingTransition (
0,
0 );
}
});
}
}


 

By gongzibai
 

 

Related Article

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.