你有两种可能的方法:采取某个开源项目并将其适应到您的需求中,或者通过详细的教程将您的刷卡器构建为图像滑块。
对于第一种选择,请在Github上查看,您会发现几个小型项目,这些项目通常使用垂直或水平滚动展示
特性。我想您可能会对以下项目感兴趣:
最后,如果您所做的附加更改看起来不错,可以值得向原始项目提交补丁。
对于第二种选择,如果您愿意从头开始实现它,那么请采取简单的步骤,根据您的意愿将项目逐渐发展成更具体/复杂的细节并进行自定义。一个全屏图像滑块会很合适,它将包括视图页面的活动:
activity_fullscreen_view.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:orientation="vertical" >
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
还有一个全屏查看器的Java类
public class FullScreenImageAdapter extends PagerAdapter {
private Activity _activity;
private ArrayList<String> _imagePaths;
private LayoutInflater inflater;
public FullScreenImageAdapter(Activity activity,
ArrayList<String> imagePaths) {
this._activity = activity;
this._imagePaths = imagePaths;
}
@Override
public int getCount() {
return this._imagePaths.size();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == ((RelativeLayout) object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
ImageView imgDisplay;
Button btnClose;
inflater = (LayoutInflater) _activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View viewLayout = inflater.inflate(R.layout.layout_fullscreen_image, container,
false);
imgDisplay = (ImageView) viewLayout.findViewById(R.id.imgDisplay);
btnClose = (Button) viewLayout.findViewById(R.id.btnClose);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bitmap = BitmapFactory.decodeFile(_imagePaths.get(position), options);
imgDisplay.setImageBitmap(bitmap);
btnClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
_activity.finish();
}
});
((ViewPager) container).addView(viewLayout);
return viewLayout;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager) container).removeView((RelativeLayout) object);
}
}
然后您可以实现图片水平滑动
(如下):
要添加垂直运动,只需包含附加的垂直布局即可。
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Swipe Demo"
android:gravity="center"
android:layout_margin="10dip" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:layout_margin="10dip"
android:id="@+id/image_place_holder"/>
</LinearLayout>
</LinearLayout>
这将允许您垂直地滑动物品:
在一天结束时,你希望拥有的是一个网格,例如垂直和水平滚动。为此,您必须将垂直和水平滑动结合到 表格布局中:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent">
<TableLayout
android:id="@+id/amortization"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TableRow
android:background="#ffff00">
<TextView
android:text="@string/amortization_1"
android:padding="3dip"/>
<TextView
android:text="@string/amortization_2"
android:padding="3dip"/>
<TextView
android:text="@string/amortization_3"
android:padding="3dip"/>
<TextView
android:text="@string/amortization_4"
android:padding="3dip"/>
<TextView
android:text="@string/amortization_5"
android:padding="3dip"/>
<TextView
android:text="@string/amortization_6"
android:padding="3dip"/>
<TextView
android:text="@string/amortization_7"
android:padding="3dip"/>
</TableRow>
</TableLayout>
</HorizontalScrollView>
</ScrollView>
采取这些步骤并将其结合起来,将使您实现所需的效果。