人们如何在水平ScrollView中自然猜测滚动?

时间:2018-10-05 07:47:31

标签: android android-viewpager scrollview android-scrollview swiperefreshlayout

我担心应用程序的UX方面。 enter image description here

我希望滚动图像作为用户的猜测。

如果我将绝对滚动到直线,则水平滚动良好,否则,将垂直滚动。这不是我想要的。

如果我单击图像区域并水平滚动,则图像必须水平滚动,但是大多数用户并不总是沿绝对直线方向滚动。

下面是我的xml代码。

<android.support.v4.widget.SwipeRefreshLayout
            android:id="@+id/swipe_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_below="@id/layoutTop"
            android:visibility="@{isFirstAccess ? View.GONE : View.VISIBLE , default = gone}">


            <ScrollView
                android:id="@+id/scrollView"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:descendantFocusability="beforeDescendants"
                    android:focusable="true"
                    android:focusableInTouchMode="true"
                    android:orientation="vertical">

                    <!-- Area of Images -->
                    <RelativeLayout
                        android:id="@+id/layoutViewPager"
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:background="@color/gray">

                        <android.support.v4.view.ViewPager
                            android:id="@+id/viewpager"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent">
                            <!-- This is area to added images. -->
                        </android.support.v4.view.ViewPager>

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="32dp"
                            android:layout_alignParentBottom="true"
                            android:layout_alignParentRight="true"
                            android:layout_margin="15dp"
                            android:background="@drawable/img_imge_count_background"
                            android:gravity="center"
                            android:minWidth="55dp"
                            android:paddingLeft="10dp"
                            android:paddingRight="10dp"
                            android:text='@{pageCount + "/" + imageListCount, default="0/0" }'
                            android:textColor="@color/lowGray"
                            android:visibility="@{pageCount == null ? View.GONE : View.VISIBLE}" />

                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_alignParentBottom="true"
                            android:layout_marginBottom="10dp"
                            android:layout_marginLeft="10dp"
                            android:alpha="0.25"
                            android:gravity="left"
                            android:paddingLeft="5dp"
                            android:text='@{currentPageImageFrom, default=""}'
                            android:textColor="@color/white"
                            android:textSize="11sp" />

                    </RelativeLayout>
                   .
                   .
                   .
                   .


class CustomPagerAdapter extends PagerAdapter {

    Context mContext;
    LayoutInflater mLayoutInflater;
    RequestOptions requestOptions;
    ArrayList<ImageView> imageViews = new ArrayList<>();

    public void onDestroy() {
        this.mContext = null;
        this.requestOptions = null;
        for (ImageView view : imageViews) {
            view.setBackground(null);
            view = null;
        }

        if (nMapContext != null)
            nMapContext.onDestroy();
    }

    public CustomPagerAdapter(Context context) {
        mContext = context;
        mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.requestOptions = new RequestOptions();


    }


    @Override
    public int getCount() {
        if (homeDetailViewModel.mImageList != null && homeDetailViewModel.mImageList.getValue() != null)
            return homeDetailViewModel.mImageList.getValue().size();
        else return 0;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == ((LinearLayout) object);
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        Log.d("kk9991", "viewpager instantiateItem:" + position);
        View itemView = mLayoutInflater.inflate(R.layout.viewpager_childview_intro, container, false);
        ImageView imageView = itemView.findViewById(R.id.imageView);
        imageView.setOnClickListener(view -> {
            goImageViewer(view);
        });
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);

        if (viewpagerImageSize == null)
            viewpagerImageSize = Utils.getResizeImageSpecForHomeDetail(homeDetailViewModel.mImageList.getValue().get(position).width, homeDetailViewModel.mImageList.getValue().get(position).height, 15.0f);

        this.requestOptions.override(viewpagerImageSize.width, viewpagerImageSize.height);

        Glide.with(mContext)
                .asBitmap()
                .load(homeDetailViewModel.mImageList.getValue().get(position).src)
                .apply(this.requestOptions)
                .into(new SimpleTarget<Bitmap>() {
                    @Override
                    public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
                        imageView.setImageBitmap(Utils.getCenterCropImage(resource));
                    }
                });
        container.addView(itemView);
        imageViews.add(imageView);

        return itemView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((LinearLayout) object);
    }


}

需要帮助。 谢谢你:)

1 个答案:

答案 0 :(得分:0)

如果您尝试将scrollview显示为水平,则使用下面的代码。

    <ScrollView
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">
</ScrollView>

Listview滚动视图为水平,然后在下面的代码中使用。

    <HorizontalScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ListView
        android:id="@+id/mylist"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1" >
    </ListView>
</HorizontalScrollView>

如果您使用了Recyclerview,则只能通过下面的行。

        mRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, true));