Android滑动屏幕
来源:互联网 发布:淘宝刷手退款能报警 编辑:程序博客网 时间:2024/05/22 15:40
自已学习了一下. 原理的东西咱不会讲, 会误倒别人. 只能上代码了.
用的Android Stdio 1.0.2 , (一看就是外行啊.哈哈..兴趣使然..)
MainActivity.java
package com.example.youtwo.testapp;import android.support.v4.view.PagerAdapter;import android.support.v4.view.ViewPager;import android.support.v7.app.ActionBarActivity;import android.os.Bundle;import android.view.LayoutInflater;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.view.ViewGroup;import java.util.ArrayList;import java.util.List;public class MainActivity extends ActionBarActivity { private View view1, view2, view3; private ViewPager viewPager; //对应的viewPager private List<View> viewList;//view数组 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); viewPager = (ViewPager) findViewById(R.id.viewpager); LayoutInflater inflater=getLayoutInflater(); view1 = inflater.inflate(R.layout.layout1, null); view2 = inflater.inflate(R.layout.layout2,null); view3 = inflater.inflate(R.layout.layout3, null); viewList = new ArrayList<View>();// 将要分页显示的View装入数组中 viewList.add(view1); viewList.add(view2); viewList.add(view3); PagerAdapter pagerAdapter = new PagerAdapter() { @Override public boolean isViewFromObject(View arg0, Object arg1) { return arg0 == arg1; } @Override public int getCount() { return viewList.size(); } @Override public void destroyItem(ViewGroup container, int position, Object object) { container.removeView(viewList.get(position)); } @Override public Object instantiateItem(ViewGroup container, int position) { container.addView(viewList.get(position)); return viewList.get(position); } }; viewPager.setAdapter(pagerAdapter); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); }}
布局文件 layout/activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity"> <android.support.v4.view.ViewPager android:id="@+id/viewpager" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" /></RelativeLayout>
layout/layout1.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ffffff" android:orientation="vertical"></LinearLayout>
layout/layout2.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ffff00" android:orientation="vertical"></LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ff00ff" android:orientation="vertical"></LinearLayout>
其实三个Layout也就颜色, 不一样.
使用PageAdapter实现滑动.
0 0
- Android 判断屏幕滑动
- Android 屏幕滑动事件
- Android 屏幕滑动事件
- Android 屏幕滑动事件
- Android滑动屏幕效果
- Android 屏幕滑动事件
- Android滑动屏幕
- Android 判断屏幕滑动
- android两屏幕互相滑动
- android手势滑动屏幕问题
- android屏幕监控上下左右滑动
- android两屏幕互相滑动
- android屏幕监控上下左右滑动
- Android Viewpage禁止滑动屏幕
- Android屏幕切换左右滑动
- Android屏幕切换左右滑动
- Android ViewFlipper滑动屏幕切换
- android屏幕的滑动监听。
- 1031.Hello World for U
- 数据库备份操作,早就不用SQLDMO了
- com.itextpdf.text.html.simpleparser.CellWrapper cannot be cast to com.itextpdf.text.Paragraph
- Oracle中job的实例
- ARM Fundamentals: Introduction to understanding ARM processors
- Android滑动屏幕
- 现在有T1、T2、T3三个线程,你怎样保证T2在T1执行完后执行,T3在T2执行完后执行
- 用GDB调试程序(二)
- 思杰desktop7.6申请90天试用的License
- 初来炸到,请多多关照
- 在liferay strut2中如何使用session
- 1032.Sharing
- hdu 3530 单调队列水题
- linux系统/var/log目录下的信息详解