標籤:android
一.360介面的實現:
看了別人的源碼從而又完善了一下,這種介面實現起來還是不麻煩的(要源碼的留下郵箱,我給你們發)。
:
主介面:
public class MainActivity extends Activity {private ImageView ivOne;private ImageView ivTwo;private ImageView button1;private ImageView button2;private ImageView button3;private ImageView button4;/* * AccelerateInterpolator 在動畫開始的時候速率改變比較慢,然後開始加速 BounceInterpolator * 動畫結束的時候彈起 DecelerateInterpolator 在動畫開始的時候快,然後變慢 。。。 */// 動畫加速private Interpolator accelerator = new AccelerateInterpolator();// 動畫減速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() {// 頁數按鈕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);// 監聽滑動vpMain.setOnPageChangeListener(listener);LinearLayout activity_main_one_layout = (LinearLayout)viewOne.findViewById(R.id.activity_main_one_layout);for (int i = 0; i < activity_main_one_layout.getChildCount(); 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, "第"+ii+"行,第"+jj+"個", Toast.LENGTH_SHORT).show();}});}}}public void setListener() {ivOne.setOnClickListener(new ImageViewOnClickListener());ivTwo.setOnClickListener(new ImageViewOnClickListener());button1.setOnClickListener(new ImageViewOnClickListener());button2.setOnClickListener(new ImageViewOnClickListener());button3.setOnClickListener(new ImageViewOnClickListener());button4.setOnClickListener(new ImageViewOnClickListener());}// 點擊ImageView,兩個頁面的切換方法private void flipit(View one, View two) {final View visible;final View invisible;// 判斷兩個view那個是隱藏的,然後切換if (one.getVisibility() == View.GONE) {visible = two;invisible = one;} else {invisible = two;visible = one;}// 設定動畫,以X軸旋轉ObjectAnimator visToInvis = ObjectAnimator.ofFloat(visible,"rotationX", 0f, 90f);// 設定時間visToInvis.setDuration(500);// 設定動畫變化速率visToInvis.setInterpolator(accelerator);final ObjectAnimator invisToVis = ObjectAnimator.ofFloat(invisible,"rotationX", -90f, 0f);invisToVis.setDuration(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();} //適配器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);}} //滑動監聽class MyListener implements OnPageChangeListener {// 手指操作螢幕的時候發生變化@Overridepublic void onPageScrollStateChanged(int arg0) {}// 在螢幕滾動過程中不斷被調用@Overridepublic void onPageScrolled(int arg0, float arg1, int arg2) {}// 手指滑動翻頁的時候,滑動的距離夠長,手指抬起來就會立即執行這個方法,arg0是頁數@Overridepublic void onPageSelected(int arg0) {flipit(ivOne, ivTwo);}} //ImageView監聽class ImageViewOnClickListener implements View.OnClickListener {@Overridepublic void onClick(View arg0) {switch (arg0.getId()) {case R.id.button1:Toast.makeText(MainActivity.this, "我要下載", Toast.LENGTH_SHORT).show();break;case R.id.button2:Toast.makeText(MainActivity.this, "我要刪除", Toast.LENGTH_SHORT).show();break;case R.id.button3:Toast.makeText(MainActivity.this, "我要設定", Toast.LENGTH_SHORT).show();break;case R.id.button4:Toast.makeText(MainActivity.this, "我要添加", Toast.LENGTH_SHORT).show();break;case R.id.viewpager_one:flipit(ivOne, ivTwo);//setCurrentItem選中頁數,getCurrentItem返回當前頁數vpMain.setCurrentItem((vpMain.getCurrentItem() + 1) % views.size());break;case R.id.viewpager_two:flipit(ivOne, ivTwo);vpMain.setCurrentItem((vpMain.getCurrentItem() + 1) % views.size());break;}}}}
主介面布局:
<?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="哈哈哈哈" android:textColor="#aaffffff" android:textScaleX="1.2" android:textSize="20sp" > </TextView> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="哈哈哈哈哈哈哈哈" android:textColor="#88ffffff" 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></RelativeLayout>
左布局:
<?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>
第一頁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>
第二頁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>
另外三個xml一樣。
android(7) 360介面的實現