【问题标题】:How to scroll natural that people guess in Horizontal ScrollView?如何在Horizo​​ntal ScrollView中自然滚动人们猜测的?
【发布时间】:2018-10-05 07:47:30
【问题描述】:

我担心我的应用程序的用户体验方面。

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

如果我绝对滚动到直线,它会很好地水平滚动,但如果我不这样做,它会垂直滚动。这不是我想要的。

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

下面是我的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);
    }


}

需要帮助。 谢谢你:)

【问题讨论】:

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


    【解决方案1】:

    如果您尝试将滚动视图显示为水平然后在下面的代码中使用..

        <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));
    

    【讨论】:

    • 我使用的 ScrollView 是垂直的。图片的滑块是 xml 中的 ViewPager。它水平滚动良好(如果我滚动到直线),但我会滚动到对角线,它是垂直滚动的。这不是自然的。
    • 表示你想要图片的滑块。
    猜你喜欢
    • 2021-03-30
    • 1970-01-01
    • 2016-12-01
    • 2015-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-30
    相关资源
    最近更新 更多