I am trying to design one screen which contain some swipe part. I have one screen with mapview, listview and some text. My Mapview is main part of swipe, if i swipe at left then contact will shown and if i swipe right then address will be display.
Here is my image. i am showing rounded part which i need to swipe. ![enter image description here](https://i.stack.imgur.com/bYYLm.png)
How can i implement this functionality in my app. I go through with one tutorial but it didn't help me. This tutorial teach how to swipe full screen but i need to swipe some part of the screen.
Is it possible. Give me some reference or hint. I didn't understand viewPager
.
最后我得到了滑动屏幕某些部分的答案。
在 onCreate() 中,您需要添加以下行
MyPagerAdapter adapter = new MyPagerAdapter();
myPager = (ViewPager) findViewById(R.id.myfivepanelpager);
myPager.setAdapter(adapter);
myPager.setCurrentItem(3);
我在我的班级中扩展了 PagerAdapter 类。
private class MyPagerAdapter extends PagerAdapter {
public int getCount() {
return 3;
}
public Object instantiateItem(View collection, int position) {
LayoutInflater inflater = (LayoutInflater) collection.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
int resId = 0;
switch (position) {
case 0:
resId = showHotelContact();
break;
case 1:
resId = showHotelAddress();
break;
case 2:
resId = showHotelMap();
break;
}
View view = inflater.inflate(resId, null);
((ViewPager) collection).addView(view, 0);
return view;
}
}
public int showHotelMap()
{
int resId;
resId = R.layout.hotelmap;
return resId;
}
public int showHotelAddress()
{
int resId;
resId = R.layout.hoteladdress;
return resId;
}
public int showHotelContact()
{
int resId;
resId = R.layout.hotelcontact;
return resId;
}
这是我的 xml 文件
?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.support.v4.view.ViewPager
android:id="@+id/myfivepanelpager"
android:layout_width="wrap_content"
android:layout_height="186dp"
android:fadingEdge="vertical" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hotelName" />
</LinearLayout>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)