标签: horizontalscrollview

ScrollView Touch Handling中的Horizo​​ntalScrollView

我有一个ScrollView环绕我的整个布局,以便整个屏幕可滚动.我在这个ScrollView中的第一个元素是一个Horizo​​ntalScrollView块,它具有可以水平滚动的功能.我在horizo​​ntalscrollview中添加了一个ontouchlistener来处理触摸事件并强制视图"捕捉"到ACTION_UP事件上最近的图像.

所以我想要的效果就像股票android主屏幕,你可以从一个滚动到另一个,当你举起手指时,它会捕捉到一个屏幕.

这一切都很有效,除了一个问题:我需要从左到右几乎完全水平滑动,以便ACTION_UP进行注册.如果我至少垂直滑动(我认为许多人往往会在他们的手机上左右滑动),我会收到ACTION_CANCEL而不是ACTION_UP.我的理论是,这是因为横向视图滚动视图位于滚动视图内,并且滚动视图正在劫持垂直触摸以允许垂直滚动.

如何在水平滚动视图中禁用滚动视图的触摸事件,但仍允许在滚动视图中的其他位置正常垂直滚动?

这是我的代码示例:

   public class HomeFeatureLayout extends HorizontalScrollView {
    private ArrayList<ListItem> items = null;
    private GestureDetector gestureDetector;
    View.OnTouchListener gestureListener;
    private static final int SWIPE_MIN_DISTANCE = 5;
    private static final int SWIPE_THRESHOLD_VELOCITY = 300;
    private int activeFeature = 0;

    public HomeFeatureLayout(Context context, ArrayList<ListItem> items){
        super(context);
        setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
        setFadingEdgeLength(0);
        this.setHorizontalScrollBarEnabled(false);
        this.setVerticalScrollBarEnabled(false);
        LinearLayout internalWrapper = new LinearLayout(context);
        internalWrapper.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
        internalWrapper.setOrientation(LinearLayout.HORIZONTAL);
        addView(internalWrapper);
        this.items = items;
        for(int i = 0; i< items.size();i++){
            LinearLayout featureLayout = (LinearLayout) View.inflate(this.getContext(),R.layout.homefeature,null);
            TextView header = (TextView) …
Run Code Online (Sandbox Code Playgroud)

android horizontalscrollview ontouchlistener android-scrollview

224
推荐指数
7
解决办法
13万
查看次数

如何实现像Gallery这样的Horizo​​ntalScrollView?

我想实现Horizontal ScrollViewGallery的一些功能, 在此输入图像描述

在画廊中,卷轴在一定距离处成对排列,即如果我们在屏幕上显示三个图像,则单击最后一个图像将排列在中心.

我将如何实施HorizontalSCrollView

android horizontalscrollview android-gallery

70
推荐指数
2
解决办法
16万
查看次数


SwipeRefreshLayout中的Horizo​​ntalScrollView

我实现了新的SwipeRefreshLayout成分在我的应用程序,它与任何垂直意见工作得很好,比如ListView,GridViewScrollView.

它在水平视图中表现得很糟糕,比如HorizontalScrollView.向右或向左滚动时,SwipeRefreshLayout视图会缓存触摸,阻止HorizontalScrollView接收并开始垂直滚动以执行刷新.

我尝试解决这个问题,因为我之前解决了ScrollViewViewPager内部垂直问题,使用requestDisallowInterceptTouchEvent但它没有用.我还注意到,在原始SwipeRefreshLayout类中重写此方法而不返回super.谷歌的开发者留下了评论" //Nope.":)

因为SwipeRefreshLayout组件相对较新,我找不到修复水平滚动问题的解决方案,同时仍然允许滑动刷新视图以跟踪和处理垂直滚动,所以我想我会分享我的解决方案,希望它会让人节省一个小时或两个.

android horizontalscrollview swiperefreshlayout

50
推荐指数
2
解决办法
1万
查看次数

Android:Horizo​​ntalScrollView smoothScroll动画时间

我有一个情况,我使用水平滚动视图与图像和使用按钮平滑滚动到不同的图像位置.现在它工作正常我只是想知道是否有人知道无论如何减慢平滑滚动方法,即有更长的动画时间?目前,这种捕捉很快就会发生.

也许通过覆盖smoothscroll,我试图搜索这个/例子,但没有运气.

那么任何想法?

谢谢,

android smooth-scrolling horizontalscrollview

27
推荐指数
4
解决办法
4万
查看次数

具有居中元素的Horizo​​ntalScrollView

我有一个使用TextViews动态填充的Horizo​​ntalScrollView.有时会有一个,两个,三个或更多元素.我正在寻找的是一种让项目居中的方法,无论元素的数量如何.

例如,使用一个元素:

| --------- MenuA --------- |
Run Code Online (Sandbox Code Playgroud)

有两个要素:

| ---- MenuA --- MenuB ---- |
Run Code Online (Sandbox Code Playgroud)

有三个要素:

| - MenuA - MenuB - MenuC - |
Run Code Online (Sandbox Code Playgroud)

有五个元素(MenuD和MenuE隐藏):

| MenuA - MenuB - MenuC - Me|
Run Code Online (Sandbox Code Playgroud)

更新:这是一个带有两个菜单的简单布局.如何将MenuA和MenuB居中?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <HorizontalScrollView android:id="@+id/horizontalScrollView1"
        android:layout_width="wrap_content" android:layout_height="wrap_content">
        <LinearLayout android:id="@+id/linearLayout1"
            android:layout_width="fill_parent" android:layout_height="fill_parent"
            android:orientation="horizontal">
            <TextView android:text="MenuA" android:id="@+id/textView1"
                android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
            <TextView android:text="MenuB" android:id="@+id/textView2"
                android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
        </LinearLayout>
    </HorizontalScrollView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

android horizontalscrollview

23
推荐指数
1
解决办法
1万
查看次数

如何以编程方式滚动Horizo​​ntalScrollView

我有一个HorizontalScrollView包含一个RelativeLayout.此布局在XML中为空,并在onCreate中从java填充.

我希望这个滚动视图最初位于中间的某个位置RelativeLayout,这比屏幕大.

我试过mHorizScrollView.scrollTo(offsetX, 0);哪个不起作用.我不知道这有什么问题.

我可以发布代码,但它并不真正相关.重要的是一切都是以编程方式完成的(必须:s),并且HorizontalScrollView必须以编程方式设置初始位置.

谢谢阅读.请告诉我您是否需要更多详细信息,或者这是否不够清楚.

android horizontal-scrolling horizontalscrollview

21
推荐指数
4
解决办法
3万
查看次数

水平scrollview捕捉反应原生

嗨,我正在努力实现scrollview像下面的gif链接中心

检查这个Gif

但无法这样做.以下是我的反应本机代码来实现这一点.

或者有没有任何方法可以滚动到像android这样的scrollview元素的特定索引?

任何帮助,将不胜感激.提前致谢

<ScrollView
  style={[styles.imgContainer,{backgroundColor:colorBg,paddingLeft:20}]}
  automaticallyAdjustInsets={false}
  horizontal={true}
  pagingEnabled={true}
  scrollEnabled={true}
  decelerationRate={0}
  snapToAlignment='center'
  snapToInterval={DEVICE_WIDTH-100}
  scrollEventThrottle={16}
  onScroll={(event) => {
    var contentOffsetX=event.nativeEvent.contentOffset.x;
    var contentOffsetY=event.nativeEvent.contentOffset.y;

    var  cellWidth = (DEVICE_WIDTH-100).toFixed(2);
    var cellHeight=(DEVICE_HEIGHT-200).toFixed(2);

    var  cellIndex = Math.floor(contentOffsetX/ cellWidth);

    // Round to the next cell if the scrolling will stop over halfway to the next cell.
    if ((contentOffsetX- (Math.floor(contentOffsetX / cellWidth) * cellWidth)) > cellWidth) {
      cellIndex++;
    }

    // Adjust stopping point to exact beginning of cell.
    contentOffsetX = cellIndex * cellWidth; …
Run Code Online (Sandbox Code Playgroud)

horizontalscrollview ios react-native react-native-scrollview

21
推荐指数
2
解决办法
2万
查看次数

Android设置hortizontal scrollview的位置

我正在尝试设置水平滚动视图的位置,因此它与按下的按钮相对应.我尝试使用它来设置它失败:

HorizontalScrollView hsv = (HorizontalScrollView)findViewById(R.id.ScrollView);
int x, y;
x = hsv.getLeft();
y = hsv.getTop();
hsv.scrollTo(x, y);
Run Code Online (Sandbox Code Playgroud)

这没有任何结果,滚动视图不受影响.xml:

 <HorizontalScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/ScrollView"
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true"
        android:background="@null"
        android:scrollbars="none" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="horizontal" >

            <Button
                android:layout_width="100dp"
                android:layout_height="fill_parent"
                android:layout_marginBottom="-5dp"
                android:text="btn0" 
                android:id="@+id/btn0"
                android:background="@drawable/yellow_btn" />

            <Button
                android:layout_width="100dp"
                android:layout_height="fill_parent"
                android:layout_marginBottom="-5dp"
                android:background="@drawable/yellow_btn"
                android:text="bnt1"
                android:id="@+id/btn1" />

            <Button
                android:layout_width="100dp"
                android:layout_height="fill_parent"
                android:layout_marginBottom="-5dp"
                android:background="@drawable/yellow_btn"
                android:text="btn2"
                android:id="@+id/btn2" />

            <Button
                android:layout_width="100dp"
                android:layout_height="fill_parent"
                android:layout_marginBottom="-5dp"
                android:background="@drawable/yellow_btn"
                android:text="btn3"
                android:id="@+id/btn3" />

      <Button
                android:layout_width="100dp"
                android:layout_height="fill_parent"
                android:layout_marginBottom="-5dp"
                android:background="@drawable/yellow_btn"
                android:text="btn4"
                android:id="@+id/btn4" />

      <Button
                android:layout_width="100dp"
                android:layout_height="fill_parent"
                android:layout_marginBottom="-5dp"
                android:background="@drawable/yellow_btn"
                android:text="btn5"
                android:id="@+id/btn5" />

        </LinearLayout> …
Run Code Online (Sandbox Code Playgroud)

android position horizontalscrollview

16
推荐指数
2
解决办法
3万
查看次数

线性布局的选框效果

我正在尝试对布局实现选框效果,以帮助它从右侧内侧向左侧内侧滚动/动画,就像自动收报机视图一样.

从以下两个链接中,您可以获得更多知识,就像股票市场通过以循环常量方式显示值来更新用户一样.

1)http://www.sify.com/finance/livemarkets/

2)http://terminal.moneycontrol.com/index.php?wl=indices

为此,我已经实现了下面的代码,使其有些类似.

public class HorizonalSlideActivity extends Activity
{
    private LinearLayout horizontalOuterLayout;
    private HorizontalScrollView horizontalScrollview;
    private int scrollMax;
    private int scrollPos = 0;
    private TimerTask scrollerSchedule;
    private Timer scrollTimer = null;
    private ScrollAdapter adapter = null;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.horizontal_layout);

        adapter = new ScrollAdapter(HorizonalSlideActivity.this);

        horizontalScrollview = (HorizontalScrollView) findViewById(R.id.horiztonal_scrollview_id);
        horizontalScrollview.setOnTouchListener(new OnTouchListener()
        {
            @Override
            public boolean onTouch(View v, MotionEvent event)
            {
                return false;
            }
        });
        horizontalOuterLayout = (LinearLayout) findViewById(R.id.horiztonal_outer_layout_id);
        horizontalTextView = (TextView) findViewById(R.id.horizontal_textview_id);
        horizontalScrollview.setHorizontalScrollBarEnabled(false); …
Run Code Online (Sandbox Code Playgroud)

android marquee horizontalscrollview android-animation android-linearlayout

16
推荐指数
2
解决办法
2994
查看次数