我使用这个library成功获得一个垂直图像滑块,工作正常。只有我坚持的部分才能垂直滑动。现在我必须水平滑动以使我的图像滑动,如here所示,但我想垂直滑动所以你知道它是有道理的。提前感谢你能解决这个问题的人,我到处寻找:)
customSwipedapter.java
public class customSwipeAdapter extends PagerAdapter {
private int[] images = {R.drawable.img1, R.drawable.img2, R.drawable.img3};
private Context ctx;
private LayoutInflater layoutInflator;
public customSwipeAdapter(Context ctx) {
this.ctx = ctx;
}
@Override
public int getCount() {
return images.length;
}
@Override
public boolean isViewFromObject(View view, Object o) {
return (view == (RelativeLayout)o);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
layoutInflator = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View item_view = layoutInflator.inflate(R.layout.swipe_layout, container, false);
ImageView imageView = (ImageView) item_view.findViewById(R.id.image_view);
imageView.setImageResource(images[position]);
container.addView(item_view);
return item_view;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((RelativeLayout)object);
}
}
mainActivity.java
public class savedImagesViewController extends AppCompatActivity {
ViewPager viewPager;
customSwipeAdapter adapter;
Bitmap bitmap ;
Thread thread ;
String evalue;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_saved_cards_view_controller);
EditText e1 = (EditText) findViewById(R.id.editText);
viewPager = (ViewPager) findViewById(R.id.view_pager);
adapter = new customSwipeAdapter(this);
viewPager.setAdapter(adapter);
viewPager.setPageTransformer(false, new DefaultTransformer());
}
}
mainActivity.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.project_bc.project_bc.savedImagesViewController">
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</android.support.v4.view.ViewPager>
</android.support.v4.widget.DrawerLayout>
swipe_layout.xml
<?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"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ImageView
android:id="@+id/image_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="15dp"
android:background="@drawable/cardborder"
android:scaleType="fitXY"
android:onClick="onClick_FlipImage"
app:srcCompat="@drawable/bcard1" />
</RelativeLayout>