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

我正在建立一个需要“卡片”UI部件的 Android应用程序.

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

1)垂直滑动支持

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

2)水平滑动支持

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

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

例:

[A1][Card1][B1]
[A2][Card2][B2]
[A3][Card3][B3]

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

解决方法

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

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

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

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

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

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>

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

相关文章

这篇“android轻量级无侵入式管理数据库自动升级组件怎么实现...
今天小编给大家分享一下Android实现自定义圆形进度条的常用方...
这篇文章主要讲解了“Android如何解决字符对齐问题”,文中的...
这篇文章主要介绍“Android岛屿数量算法怎么使用”的相关知识...
本篇内容主要讲解“Android如何开发MQTT协议的模型及通信”,...
本文小编为大家详细介绍“Android数据压缩的方法是什么”,内...