Today continue to talk about the Android menu, before the introduction: I believe you are not unfamiliar with Metro style, the following on the Androping stage to achieve this effect, as shown:
realize the idea:
Using animation to achieve the effect of moving, the use of translateanimation this method. First look at the layout file:
Activity_main.xml
Copy Code code as follows:
<?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= "#000000"
android:orientation= "Vertical" >
<!--first floor-->
<linearlayout
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
android:layout_weight= "1"
android:orientation= "Horizontal" >
<!--first floor transverse-->
<!--first floor transverse left-->
<linearlayout
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
android:layout_weight= "1"
android:orientation= "Vertical" >
<linearlayout
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
android:layout_weight= "1"
android:orientation= "Horizontal" >
<!--1-->
<relativelayout
Android:id= "@+id/nine_one"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
android:layout_weight= "1"
android:background= "#FFFF00" >
</RelativeLayout>
<!--2-->
<relativelayout
Android:id= "@+id/nine_two"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
android:layout_weight= "1"
android:background= "#FFC0CB" >
</RelativeLayout>
</LinearLayout>
<!--4-->
<relativelayout
Android:id= "@+id/nine_four"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
android:layout_weight= "1"
android:background= "#EE30A7" >
</RelativeLayout>
<!--5-->
<relativelayout
Android:id= "@+id/nine_five"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
android:layout_weight= "1"
android:background= "#EE4000" >
</RelativeLayout>
</LinearLayout>
<!--first horizontal right-->
<linearlayout
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
Android:layout_weight= "2"
android:orientation= "Vertical" >
<!--3-->
<relativelayout
Android:id= "@+id/nine_three"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
Android:layout_weight= "2"
android:background= "#FF8C69" >
</RelativeLayout>
<!--6-->
<relativelayout
Android:id= "@+id/nine_six"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
android:layout_weight= "1"
android:background= "#8C8C8C" >
</RelativeLayout>
</LinearLayout>
</LinearLayout>
<!--second floor-->
<linearlayout
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
android:layout_weight= "3"
Android:baselinealigned= "false"
android:orientation= "Horizontal" >
<!--7-->
<relativelayout
Android:id= "@+id/nine_seven"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
android:layout_weight= "1"
android:background= "#8B3E2F" >
</RelativeLayout>
<!--8-->
<!--9-->
<relativelayout
Android:id= "@+id/nine_nine"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
android:layout_weight= "1"
android:background= "#A52A2A" >
</RelativeLayout>
</LinearLayout>
</LinearLayout>
The effect of this is this:
After the mainactivity inside the layout for each animation move can achieve the effect of translation.
Mainactivity.java:
Copy Code code as follows:
Import android.app.Activity;
Import android.content.Intent;
Import Android.os.Bundle;
Import Android.util.DisplayMetrics;
Import Android.view.LayoutInflater;
Import Android.view.Menu;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.view.Window;
Import android.view.animation.TranslateAnimation;
Import Android.widget.RelativeLayout;
Import Android.widget.Toast;
/**
*
*/
public class Mainactivity extends activity {
Private View Viewnine;
Private Layoutinflater Inflater;
Private Relativelayout Nine_one, Nine_two, Nine_three, Nine_four,
Nine_five, Nine_six, Nine_seven, Nine_nine;
Private Translateanimation myanimation_right, Myanimation_bottom;
Private Translateanimation myanimation_left, myanimation_top;
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Requestwindowfeature (Window.feature_no_title);
Inflater = Layoutinflater.from (this);
Viewnine = inflater.inflate (R.layout.activity_main, NULL);
Nine_one = (relativelayout) Viewnine.findviewbyid (R.id.nine_one);
Nine_two = (relativelayout) Viewnine.findviewbyid (r.id.nine_two);
Nine_three = (relativelayout) Viewnine.findviewbyid (R.id.nine_three);
Nine_four = (relativelayout) Viewnine.findviewbyid (R.id.nine_four);
Nine_five = (relativelayout) Viewnine.findviewbyid (r.id.nine_five);
Nine_six = (relativelayout) Viewnine.findviewbyid (r.id.nine_six);
Nine_seven = (relativelayout) Viewnine.findviewbyid (R.id.nine_seven);
Nine_nine = (relativelayout) Viewnine.findviewbyid (r.id.nine_nine);
Setcontentview (Viewnine);
Nine_four.setonclicklistener (New Onclicklistener () {
@Override
public void OnClick (View v) {
Intent intent=new Intent (mainactivity.this,oneactivity.class);
StartActivity (Intent);
}
});
Nine_six.setonclicklistener (New Onclicklistener () {
@Override
public void OnClick (View v) {
}
});
Myanimation ();
Addanimation ();
}
Start animation
private void Addanimation () {
Nine_one.startanimation (Myanimation_right);
Nine_two.startanimation (Myanimation_bottom);
Nine_three.startanimation (Myanimation_left);
Nine_four.startanimation (Myanimation_bottom);
Nine_five.startanimation (Myanimation_left);
Nine_six.startanimation (Myanimation_top);
Nine_seven.startanimation (Myanimation_left);
Nine_nine.startanimation (Myanimation_left);
}
Animation definition
private void Myanimation () {
Displaymetrics displaymetrics = new Displaymetrics ();
Displaymetrics = This.getresources (). Getdisplaymetrics ();
Get screen width
int screenwidth = Displaymetrics.widthpixels;
Get screen height
int screenheight = Displaymetrics.heightpixels;
Myanimation_right = new Translateanimation (screenwidth, 0, 0, 0);
Myanimation_right.setduration (1800);
Myanimation_bottom = new Translateanimation (0, 0, screenheight, 0);
Myanimation_bottom.setduration (1500);
Myanimation_left = new Translateanimation (-screenwidth, 0, 0, 0);
Myanimation_left.setduration (2000);
Myanimation_top = new Translateanimation (0, 0,-screenheight, 0);
Myanimation_top.setduration (2500);
}
@Override
public boolean Oncreateoptionsmenu (Menu menu) {
Inflate the menu; This adds items to the action bar if it is present.
Getmenuinflater (). Inflate (R.menu.activity_main, menu);
return true;
}
}
Although the effect is fine, the layout file, because it uses nesting, destroys the problem of performance when drawing the window. So you're very strict with the program, so it's recommended that you use Relativewlayout to layout and reduce the use of nesting.
Download Address