Android StackView类型的布局与水平滑动

前端之家收集整理的这篇文章主要介绍了Android StackView类型的布局与水平滑动前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在建立一个需要“卡片”UI部件的 Android应用程序.

这是一个可以执行以下操作的活动/布局示例的请求:

1)垂直滑动支持

列出可以垂直滚动/滑动的一张卡片. StackView执行此操作,但我可以使用任何可以正常工作的解决方案(例如,某些CardUI项目)

2)水平滑动支持

对于任何卡,有2个字典定义:

>如果我们做左滑动 – 那么我们可以看到定义A.
>如果我们做一个正确的滑动,我们看到定义B
>水平滑动更新不会更新整个屏幕布局,只是刷卡的卡.所以如果我在右侧刷卡2看A2,我还有一个Card1在A2后面

例:

  1. [A1][Card1][B1]
  2. [A2][Card2][B2]
  3. [A3][Card3][B3]

我确实看到这个相关的post here,这里的答案提供了一些提示和参考信息..但不幸的是,我仍然试图弄清楚.

解决方法

您有两种可能的方法:采取一些开源项目,并根据您的需要进行调整,或以其他方式,从详细教程中将您的卡片作为图片滑块构建.

对于第一个选项,请查看Github,您将在那里找到几个小型项目,它们通常在垂直或水平滚动上执行features张卡片.我想你可能会发现有趣的以下项目:

> CardDeck:适用于Android的Deck of Cards
> DeckPicker:一个完整​​的Android anki droid项目,在浏览器屏幕中有一些额外的卡预览功能.预览屏幕卡将在card browser窗口显示评论模式.

最后,如果您所做的其他更改看起来不错,那么可以向原始项目提交补丁.

对于第二种替代方案,对于这种情况,您更愿意从头开始实施,然后采取简单的步骤,将您的项目扩展到根据您的意愿定制的更具体/复杂的详细信息.全屏图像滑块将适合该帐单,其将包括视图页面的活动:

  1. activity_fullscreen_view.xml
  2. <?xml version="1.0" encoding="utf-8"?>
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4. android:layout_width="match_parent"
  5. android:layout_height="match_parent"
  6. android:orientation="vertical" >
  7.  
  8. <android.support.v4.view.ViewPager
  9. android:id="@+id/pager"
  10. android:layout_width="fill_parent"
  11. android:layout_height="fill_parent" />
  12.  
  13. </LinearLayout>

和一个Java class与全屏浏览器:

  1. public class FullScreenImageAdapter extends PagerAdapter {
  2.  
  3. private Activity _activity;
  4. private ArrayList<String> _imagePaths;
  5. private LayoutInflater inflater;
  6.  
  7. // constructor
  8. public FullScreenImageAdapter(Activity activity,ArrayList<String> imagePaths) {
  9. this._activity = activity;
  10. this._imagePaths = imagePaths;
  11. }
  12.  
  13. @Override
  14. public int getCount() {
  15. return this._imagePaths.size();
  16. }
  17.  
  18. @Override
  19. public boolean isViewFromObject(View view,Object object) {
  20. return view == ((RelativeLayout) object);
  21. }
  22.  
  23. @Override
  24. public Object instantiateItem(ViewGroup container,int position) {
  25. ImageView imgDisplay;
  26. Button btnClose;
  27.  
  28. inflater = (LayoutInflater) _activity
  29. .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  30. View viewLayout = inflater.inflate(R.layout.layout_fullscreen_image,container,false);
  31.  
  32. imgDisplay = (ImageView) viewLayout.findViewById(R.id.imgDisplay);
  33. btnClose = (Button) viewLayout.findViewById(R.id.btnClose);
  34.  
  35. BitmapFactory.Options options = new BitmapFactory.Options();
  36. options.inPreferredConfig = Bitmap.Config.ARGB_8888;
  37. Bitmap bitmap = BitmapFactory.decodeFile(_imagePaths.get(position),options);
  38. imgDisplay.setImageBitmap(bitmap);
  39.  
  40. // close button click event
  41. btnClose.setOnClickListener(new View.OnClickListener() {
  42. @Override
  43. public void onClick(View v) {
  44. _activity.finish();
  45. }
  46. });
  47.  
  48. ((ViewPager) container).addView(viewLayout);
  49.  
  50. return viewLayout;
  51. }
  52.  
  53. @Override
  54. public void destroyItem(ViewGroup container,int position,Object object) {
  55. ((ViewPager) container).removeView((RelativeLayout) object);
  56.  
  57. }
  58. }

然后你实现图像滑动horizontally,如:

添加垂直运动,只需添加垂直布局:

  1. main.xml
  2.  
  3. <?xml version="1.0" encoding="utf-8"?>
  4.  
  5. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  6.  
  7. android:layout_width="fill_parent"
  8.  
  9. android:layout_height="fill_parent"
  10.  
  11. android:orientation="vertical" >
  12.  
  13. <TextView
  14.  
  15. android:layout_width="fill_parent"
  16.  
  17. android:layout_height="wrap_content"
  18.  
  19. android:text="Swipe Demo"
  20.  
  21. android:gravity="center"
  22.  
  23. android:layout_margin="10dip" />
  24.  
  25. <LinearLayout
  26.  
  27. android:layout_width="fill_parent"
  28.  
  29. android:layout_height="fill_parent"
  30.  
  31. android:orientation="vertical"
  32.  
  33. android:gravity="center">
  34.  
  35. <ImageView
  36.  
  37. android:layout_width="wrap_content"
  38.  
  39. android:layout_height="wrap_content"
  40.  
  41. android:layout_gravity="center"
  42.  
  43. android:gravity="center"
  44.  
  45. android:layout_margin="10dip"
  46.  
  47. android:id="@+id/image_place_holder"/>
  48.  
  49. </LinearLayout>
  50.  
  51. </LinearLayout>

哪个可以让你滑动的东西vertically

在一天结束时,您想要的是一个网格,例如垂直和水平滚动在一起.因此,您必须将垂直和水平滑动组合到table layout中:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="wrap_content">
  5.  
  6. <HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  7. android:layout_width="wrap_content"
  8. android:layout_height="fill_parent">
  9.  
  10. <TableLayout
  11. android:id="@+id/amortization"
  12. android:layout_width="wrap_content"
  13. android:layout_height="wrap_content">
  14.  
  15. <TableRow
  16. android:background="#ffff00">
  17. <TextView
  18. android:text="@string/amortization_1"
  19. android:padding="3dip"/>
  20. <TextView
  21. android:text="@string/amortization_2"
  22. android:padding="3dip"/>
  23. <TextView
  24. android:text="@string/amortization_3"
  25. android:padding="3dip"/>
  26. <TextView
  27. android:text="@string/amortization_4"
  28. android:padding="3dip"/>
  29. <TextView
  30. android:text="@string/amortization_5"
  31. android:padding="3dip"/>
  32. <TextView
  33. android:text="@string/amortization_6"
  34. android:padding="3dip"/>
  35. <TextView
  36. android:text="@string/amortization_7"
  37. android:padding="3dip"/>
  38. </TableRow>
  39. </TableLayout>
  40. </HorizontalScrollView>
  41. </ScrollView>

采取这样的步骤并结合起来,将使您达到想要的效果.

猜你在找的Android相关文章