Android (7) 360 UI implementation, android360
I. 360 Implementation of the interface:
After reading other people's source code, I improved it again. This interface is not difficult to implement (I want to leave a mailbox for the source code and I will send it to you ).
:
Main Interface:
Public class MainActivity extends Activity {private ImageView ivOne; private ImageView ivTwo; private ImageView button1; private ImageView button2; private ImageView button3; private ImageView button4; /** the AccelerateInterpolator speed changes slowly at the beginning of the animation, and then starts to accelerate the BounceInterpolator * When the animation ends, the DecelerateInterpolator is faster at the beginning of the animation, and then slows down... * // Animation acceleration private Interpolator accelerator = new AccelerateInterpolator (); // animation deceleration private Interpolator decelerator = new DecelerateInterpolator (); private ViewPager vpMain; private List <View> views; private View viewOne; private View viewTwo; @ Overrideprotected void onCreate (Bundle savedInstanceState) {// TODO Auto-generated method stubsuper. onCreate (savedInstanceState); setView (); initView (); setListener ();} public void setView () {requestWindowFeature (Window. FEATURE_NO_TITLE); setContentView (R. layout. activity_main);} public void initView () {// page number button ivOne = (ImageView) findViewById (R. id. viewpager_one); ivTwo = (ImageView) findViewById (R. id. viewpager_two); button1 = (ImageView) findViewById (R. id. button1); button2 = (ImageView) findViewById (R. id. button2); button3 = (ImageView) findViewById (R. id. button3); button4 = (ImageView) findViewById (R. id. button4); // ViewPagervpMain = (ViewPager) findViewById (R. id. viewpager_main); views = new ArrayList <View> (); viewOne = View. inflate (this, R. layout. activity_main_one, null); views. add (viewOne); viewTwo = View. inflate (this, R. layout. activity_mian_two, null); views. add (viewTwo); MyAdapter adapter = new MyAdapter (); MyListener listener = new MyListener (); vpMain. setAdapter (adapter); // listens for sliding vpMain. setOnPageChangeListener (listener); LinearLayout activity_main_one_layout = (LinearLayout) viewOne. findViewById (R. id. activity_main_one_layout); for (int I = 0; I <partition (); I ++) {for (int j = 0; j <(LinearLayout) activity_main_one_layout.getChildAt (I )). getChildCount (); j ++) {final int ii = I; final int jj = j; (LinearLayout) activity_main_one_layout.getChildAt (I )). getChildAt (j ). setOnClickListener (new View. onClickListener () {@ Overridepublic void onClick (View arg0) {Toast. makeText (MainActivity. this, "th" + ii + ", th" + jj + ", Toast. LENGTH_SHORT ). show () ;}}}}}public void setListener () {ivOne. setOnClickListener (new ImageViewOnClickListener (); ivTwo. setOnClickListener (new ImageViewOnClickListener (); listener (new ImageViewOnClickListener (); button2.setOnClickListener (new ImageViewOnClickListener (); button3.setOnClickListener (new ImageViewOnClickListener ()); button4.setOnClickListener (new ImageViewOnClickListener ();} // click ImageView. The switching method of the two pages is private void flipit (View one, View two) {final View visible; final View invisible; // determine whether the two views are hidden, and then switch if (one. getVisibility () = View. GONE) {visible = two; invisible = one ;}else {invisible = two; visible = one ;}// set the animation to rotate ObjectAnimator visToInvis = ObjectAnimator on the X axis. ofFloat (visible, "rotationX", 0f, 90f); // set the time visToInvis. setDuration (500); // sets the animation change rate visToInvis. setInterpolator (accelerator); final ObjectAnimator invisToVis = ObjectAnimator. ofFloat (invisible, "rotationX",-90f, 0f); invisToVis. setDuration (1, 500); invisToVis. setInterpolator (decelerator); visToInvis. addListener (new AnimatorListenerAdapter () {@ Overridepublic void onAnimationEnd (Animator anim) {visible. setVisibility (View. GONE); invisToVis. start (); invisible. setVisibility (View. VISIBLE) ;}}); visToInvis. start ();} // adapter class MyAdapter extends PagerAdapter {@ Overridepublic int getCount () {return views. size () ;}@ Overridepublic boolean isViewFromObject (View view, Object obj) {return view = obj ;}@ Overridepublic void destroyItem (ViewGroup container, int position, Object object) {container. removeView (views. get (position) ;}@ Overridepublic Object instantiateItem (ViewGroup container, int position) {container. addView (views. get (position); return views. get (position) ;}/// sliding listening class MyListener implements OnPageChangeListener {// changes when the finger operates the screen @ Overridepublic void onPageScrollStateChanged (int arg0) {} // when the screen is continuously called during scrolling @ Overridepublic void onPageScrolled (int arg0, float arg1, int arg2) {} // when the finger slides to flip the page, if the sliding distance is long enough, the finger will immediately execute this method. arg0 is the number of pages @ Overridepublic void onPageSelected (int arg0) {flipit (ivOne, ivTwo );}} // ImageView listens to class ImageViewOnClickListener implements View. onClickListener {@ Overridepublic void onClick (View arg0) {switch (arg0.getId () {case R. id. button1: Toast. makeText (MainActivity. this, "I want to download", Toast. LENGTH_SHORT ). show (); break; case R. id. button2: Toast. makeText (MainActivity. this, "I want to delete", Toast. LENGTH_SHORT ). show (); break; case R. id. button3: Toast. makeText (MainActivity. this, "I want to set", Toast. LENGTH_SHORT ). show (); break; case R. id. button4: Toast. makeText (MainActivity. this, "I want to add", Toast. LENGTH_SHORT ). show (); break; case R. id. viewpager_one: flipit (ivOne, ivTwo); // setCurrentItem selected page number. getCurrentItem returns the current page number vpMain. setCurrentItem (vpMain. getCurrentItem () + 1) % views. size (); break; case R. id. viewpager_two: flipit (ivOne, ivTwo); vpMain. setCurrentItem (vpMain. getCurrentItem () + 1) % views. size (); break ;}}}}
Main Interface layout:
<? 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: background = "@ drawable/w6"> <LinearLayout android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: gravity = "center_vertical" android: orientation = "vertical" android: layout_margin = "10dp" android: paddingLeft = "5dp"> <LinearLayout android: id = "@ + id/title" android: layout_width = "wrap_content" android: layout_height = "60dp" android: layout_marginBottom = "10dp" android: layout_marginLeft = "15dp" android: layout_marginTop = "8dp" android: orientation = "vertical"> <TextView android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: padding = "5dp" android: text = "Hahahaha" android: textColor = "# aaffffff" android: textScaleX = "1.2" android: textSize = "20sp"> </TextView> <TextView android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "HAHAHA, hahaha" android: textColor = "#88 ffffff" android: textSize = "15sp"> </TextView> </LinearLayout> <android. support. v4.view. viewPager android: id = "@ + id/viewpager_main" android: layout_width = "wrap_content" android: layout_height = "wrap_content"/> </LinearLayout> <RelativeLayout android: layout_width = "50dp" android: layout_height = "match_parent" android: layout_alignParentRight = "true" android: paddingBottom = "30dp" android: paddingRight = "5dp" android: paddingTop = "60dp"> <include android: id = "@ + id/main_sb" android: layout_width = "wrap_content" android: layout_height = "wrap_content" layout = "@ layout/activity_main_left"/> <ImageView android: id = "@ + id/viewpager_one" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_alignParentBottom = "true" android: background = "@ drawable/rootblock_main_page_one"/> <ImageView android: id = "@ + id/viewpager_two" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_alignParentBottom = "true" android: background = "@ drawable/rootblock_main_page_two" android: visibility = "gone"/> </RelativeLayout>
Left layout:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" > <ImageView android:id="@+id/button1" android:layout_width="36dp" android:layout_height="36dp" android:src="@drawable/rootblock_icon_download_bg" /> <ImageView android:id="@+id/button2" android:layout_width="36dp" android:layout_height="36dp" android:layout_marginTop="20dp" android:src="@drawable/rootblock_icon_clear_bg" /> <ImageView android:id="@+id/button3" android:layout_width="36dp" android:layout_height="36dp" android:layout_marginTop="20dp" android:src="@drawable/rootblock_icon_set_bg" /> <ImageView android:id="@+id/button4" android:layout_width="36dp" android:layout_height="36dp" android:layout_marginTop="20dp" android:src="@drawable/rootblock_icon_add_bg" /></LinearLayout>
Page 1 view:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingBottom="30dp" android:orientation="vertical" android:id="@+id/activity_main_one_layout" > <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > <LinearLayout android:layout_width="110dp" android:layout_height="80dp" android:background="#000000"> </LinearLayout> <LinearLayout android:layout_width="110dp" android:layout_height="80dp" android:layout_marginLeft="5dp" android:background="#000000" > </LinearLayout> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:orientation="horizontal" > <LinearLayout android:layout_width="110dp" android:layout_height="80dp" android:background="#3399ff" > </LinearLayout> <LinearLayout android:layout_width="110dp" android:layout_height="80dp" android:layout_marginLeft="5dp" android:background="#3399ff" > </LinearLayout> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:orientation="horizontal" > <LinearLayout android:layout_width="110dp" android:layout_height="80dp" android:background="#3399ff" > </LinearLayout> <LinearLayout android:layout_width="110dp" android:layout_height="80dp" android:layout_marginLeft="5dp" android:background="#3399ff" > </LinearLayout> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:orientation="horizontal" > <LinearLayout android:layout_width="110dp" android:layout_height="80dp" android:background="#953399ff" > </LinearLayout> <LinearLayout android:layout_width="110dp" android:layout_height="80dp" android:layout_marginLeft="5dp" android:background="#953399ff" > </LinearLayout> </LinearLayout></LinearLayout>
Page 2 view:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:paddingBottom="30dp" > <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > <LinearLayout android:layout_width="110dp" android:layout_height="80dp" android:background="#FF7F24" > </LinearLayout> <LinearLayout android:layout_width="110dp" android:layout_height="80dp" android:layout_marginLeft="5dp" android:background="#FF7F24" > </LinearLayout> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:orientation="horizontal" > <LinearLayout android:layout_width="110dp" android:layout_height="80dp" android:background="#3399ff" > </LinearLayout> <LinearLayout android:layout_width="110dp" android:layout_height="80dp" android:layout_marginLeft="5dp" android:background="#3399ff" > </LinearLayout> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:orientation="horizontal" > <LinearLayout android:layout_width="110dp" android:layout_height="80dp" android:background="#3399ff" > </LinearLayout> <LinearLayout android:layout_width="110dp" android:layout_height="80dp" android:layout_marginLeft="5dp" android:background="#3399ff" > </LinearLayout> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:orientation="horizontal" > <LinearLayout android:layout_width="110dp" android:layout_height="80dp" android:background="#953399ff" > </LinearLayout> <LinearLayout android:layout_width="110dp" android:layout_height="80dp" android:layout_marginLeft="5dp" android:background="#953399ff" > </LinearLayout> </LinearLayout></LinearLayout>
Drawable:
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_focused="true" android:drawable="@drawable/rootblock_icon_add"></item><item android:state_pressed="true" android:drawable="@drawable/rootblock_icon_add_selected"></item><item android:state_enabled="true" android:drawable="@drawable/rootblock_icon_add"></item></selector>
The other three are the same.