您有两种可能的方法:采取一些开源项目并根据您的需要进行调整,否则,从详细教程构建您的卡片刷卡作为图像滑块。
对于第一个选项,看看Github,在那里你会发现几个小型项目,通常在垂直或水平滚动上做一副牌features。我猜你可能感兴趣的以下项目:
如果您所做的其他更改看起来不错结束时,它可以是值得补丁提交到原始项目。
对于第二种选择,对于情况下,你更愿意从头开始实现它,然后采取简单的步骤,越来越多的项目进入更具体的/复杂的细节在你的意愿进行定制。全屏图像滑块将适合该法案,这将包括用于查看页面的活动:
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 class:
public class FullScreenImageAdapter extends PagerAdapter {
private Activity _activity;
private ArrayList<String> _imagePaths;
private LayoutInflater inflater;
// constructor
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);
// close button click event
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);
}
}
然后你实现图像滑动horizontally,如:
并添加垂直运动,只是包括额外的垂直布局:
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>
,这将使你滑的东西vertically:
在这一天结束时,你想拥有的是一个网格,如垂直和水平滚动起来。对于你有水平和垂直滑动结合成一个table layout:
<?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>
采取这些步骤,并结合它,可以让你达到你想要的效果。
嗨Avanz,感谢您对您的文章和屏幕截图 - 他们帮助。你所展示的水平滑动显示全屏变化。我试图完成一个前景的视图可以水平滑动,其背后的意见仍然存在。 – gnB
啊..我现在在笔记中看到,我应该继续从已列出的入门代码进行迭代,并尝试结合不同的方法来适应手头的需求。感谢您以不同方式分享代码和想法,我可以继续使用上述方法。 – gnB
我正在尝试你的建议,使用这个项目https://github.com/cthibault/CardDeck,但我没有弄清楚如何运行代码,以便我可以看到Card&Deck UI元素。我只看到Hello World屏幕和一个非工作选项菜单。我没有将该根文件夹下的两个项目导入到ADT中,并尝试运行这两个项目。测试项目似乎只是单元测试,没有任何UI可以查看。我猜你在运行CardDeck主项目时必须能够在你的环境中看到某些东西? – gnB