【问题标题】:Issue with vertical and horizontal scroll in Xamarin Forms (Android)Xamarin Forms (Android) 中的垂直和水平滚动问题
【发布时间】:2015-02-10 21:16:47
【问题描述】:

我是 Xamarin 的新手。我正在尝试使用 5 个自定义水平列表视图在 Xamarin 表单中创建一个示例(我已经使用渲染器在不同的平台上实现相同的效果。当我在屏幕上只有 2 个这些控件时,它可以完美地工作(水平滚动)。当我添加所有5 我必须在垂直方向的 ScrollView 中添加这些控件,这样我才能看到所有控件。当我这样做时,我只能垂直滚动页面。我无法水平滚动各个控件(horizo​​ntallistviews)。

此问题仅适用于 Android。它在 Windows Phone 中运行良好。

下面是我的代码:

    <ScrollView Orientation="Vertical">
       <StackLayout Padding="5, 25" Orientation="Vertical" VerticalOptions="FillAndExpand">
          <Image Source ="label_entertainment.png" HorizontalOptions="Start"/>
          <local:HorizontalListViewEntertainment x:Name="entertainmentView" Items="{Binding Entertainment}" HeightRequest="198"/>
          <Image Source ="label_music.png" HorizontalOptions="Start"/>
          <local:HorizontalListViewMusic x:Name="musicListView" Items="{Binding Music}" HeightRequest="198"/>
          <Image Source ="label_movies.png" HorizontalOptions="Start"/>
          <local:HorizontalListViewMovies x:Name="movieListView" Items="{Binding Movies}" HeightRequest="198"/>
          <Image Source ="label_celebrities.png" HorizontalOptions="Start"/>
          <local:HorizontalListViewCelebrities x:Name="celebritiesListView" Items="{Binding Celebrities}" HeightRequest="198"/>
          <Image Source ="label_style.png" HorizontalOptions="Start"/>
          <local:HorizontalListViewStyle x:Name="styleListView" Items="{Binding Celebrities}" HeightRequest="198"/>
      </StackLayout>
  </ScrollView>

我找到了解决方案here。但是在我的情况下它不起作用,因为我没有内部滚动视图。请帮忙。谢谢!

【问题讨论】:

    标签: xamarin xamarin.forms


    【解决方案1】:

    我找到了解决方案。我只需要将以下代码添加到android中的horizo​​ntallistviews的CustomRenderer。

    public override bool DispatchTouchEvent(MotionEvent e)
        {
            switch (e.Action)
            {
                case MotionEventActions.Down:
                    StartX = e.RawX;
                    StartY = e.RawY;
                    this.Parent.RequestDisallowInterceptTouchEvent(true);
                    break;
                case MotionEventActions.Move:
                    if (IsHorizontal * Math.Abs(StartX - e.RawX) < IsHorizontal * Math.Abs(StartY - e.RawY))
                        this.Parent.RequestDisallowInterceptTouchEvent(false);
                    break;
                case MotionEventActions.Up:
                    this.Parent.RequestDisallowInterceptTouchEvent(false);
                    break;
            }
            return base.DispatchTouchEvent(e);
        }
    

    推荐this

    【讨论】:

      【解决方案2】:

      您是否尝试过同时使用 ScrollView 和 Horizo​​ntalScrollView ? http://android-code-crumbs.blogspot.ro/2011/06/how-to-set-horizontal-and-vertical.html

      【讨论】:

        猜你喜欢
        • 2022-08-14
        • 1970-01-01
        • 2016-10-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-01-09
        相关资源
        最近更新 更多