微软存放位置在哪里
851
2022-05-30
public class ViewPager_2Activity extends Activity
{
private List
private ViewPager viewPager;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
listViews = new ArrayList
listViews.add(View.inflate(getApplicationContext(), R.layout.layout1,
null));
listViews.add(View.inflate(getApplicationContext(), R.layout.layout2,
null));
listViews.add(View.inflate(getApplicationContext(), R.layout.layout3,
null));
viewPager = (ViewPager) findViewById(R.id.v_Pager);
viewPager.setAdapter(new MyPagerAdapter(listViews));
viewPager.setCurrentItem(0);
View view = listViews.get(2);
TextView textView = (TextView) view.findViewById(R.id.text_3);
textView.setText("10");
Button button = (Button) view.findViewById(R.id.button_3);
button.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "你点击了按钮",
Toast.LENGTH_SHORT).show();
}
});
}
private class MyPagerAdapter extends PagerAdapter
{
private List
private MyPagerAdapter(List
{
// TODO Auto-generated method stub
this.mListView = list;
}
@Override
/**这个方法,是从ViewGroup中移出当前View**/
public void destroyItem(View container, int position, Object object)
{
// TODO Auto-generated method stub
((ViewGroup) container ).removeView(mListView.get(position));
}
@Override
public void finishUpdate(View view)
{
// TODO Auto-generated method stub
}
@Override
/**这个方法,是获取当前窗体界面数**/
public int getCount()
{
// TODO Auto-generated method stub
return mListView.size();
}
@Override
/**这个方法,return一个对象,这个对象表明了PagerAdapter适配器选择哪个对象*放在当前的ViewPager中**/
public Object instantiateItem(View container, int position)
{
// TODO Auto-generated method stub
((ViewGroup) container).addView(mListView.get(position), 0);
return mListView.get(position);
}
@Override
/**这个方法,在帮助文档中原文是could be implemented as return view == object,*也就是用于判断是否由对象生成界面**/
public boolean isViewFromObject(View view, Object object)
{
// TODO Auto-generated method stub
return view == (object);
}
@Override
public void restoreState(Parcelable state, ClassLoader loader)
{
// TODO Auto-generated method stub
}
@Override
public Parcelable saveState()
{
// TODO Auto-generated method stub
return null;
}
@Override
public void startUpdate(View v)
{
// TODO Auto-generated method stub
}
}
}
android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > android:id="@+id/v_Pager" android:layout_width="fill_parent" android:layout_height="fill_parent" >
android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="15" android:textSize="150sp" android:layout_gravity="center_horizontal"/>
android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="25" android:textSize="150sp" android:layout_gravity="center_horizontal"/>
android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="35" android:textSize="150sp" android:layout_gravity="center_horizontal"/>
效果图:
ViewPager页面拖动到最前或最后的时候回弹效果
看到一哥们用ViewPager写的左右滑动的屏幕,像UC浏览器那样,连接:
http://www.eoeandroid.com/thread-92508-1-1.html
但是当滑到最左端或者最右端就不能滑动了,感觉用户体验不如UC的,所以就试着弄了下
继承ViewPager类以后,在左面和右面各增加个空View,然后在onPageSelected方法中
@Override
public void onPageSelected(int arg0)
{
// TODO Auto-generated method stub
System.out.println("onPageSelected = " + arg0);
if (arg0 == 0)
mViewPaper.setCurrentItem(arg0 + 1);
else if (arg0 == mViewList.size() - 1)
mViewPaper.setCurrentItem(arg0 - 1);
}
onPageSelected(int arg0){
}
arg0是表示你当前选中的页面,这事件是在你页面跳转完毕的时候调用的。
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub
} arg0 ==1的时候表示正在滑动,arg0==2的时候表示滑动完毕了,arg0==0的时候表示什么都没做,就是停在那。
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
}表示在前一个页面滑动到后一个页面的时候,在前一个页面滑动前调用的方法。
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。