【问题标题】:Xamarin Scroll-View is supposed to jump to bottomXamarin Scroll-View 应该跳到底部
【发布时间】:2018-08-22 15:49:04
【问题描述】:

我有一个ViewSwitcher,其中我有一个TextView,周围是一个ScrollView,用于获取滚动条。我需要它自动滚动到底部。是否有某种财产可以做到这一点?我已经尝试过将重力放在底部。

这是我的代码:

<ScrollView
        android:id="@+id/SCROLLER_ID"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scrollbars="vertical"
        android:fillViewport="true">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/textView1"
            android:clickable="true"
            android:fadeScrollbars="false"
            android:scrollbars="vertical"
            android:scrollbarAlwaysDrawVerticalTrack="true"
            android:verticalScrollbarPosition="right"
            android:longClickable="true"
            android:nestedScrollingEnabled="true"
            android:layout_marginRight="15.5dp"
            android:layout_marginLeft="0.0dp" />
    </ScrollView>
</ViewSwitcher>

【问题讨论】:

  • 你能提供你到目前为止所做的代码吗?
  • @Benjamin 我提供了代码!

标签: c# android xml xamarin


【解决方案1】:

我不认为你可以在你的 AXML 中做到这一点。在我看来,您必须在代码隐藏中执行此操作。在布局文件对应的activity中,请在你的OnCreate override中加入如下sn -p:

var scrollView = FindViewById<ScrollView>(Resource.Id.SCROLLER_ID);
scrollView.Post(() =>
{
    scrollView.FullScroll(FocusSearchDirection.Down);
});

您可能必须使用Post()PostDelayed(),试一试。另请查看文档中的fullScroll() 方法。

如果上述方法不起作用,另一种方法是在 ScrollView 上调用 scrollTo(),如下所示:

var scrollView = FindViewById<ScrollView>(Resource.Id.SCROLLER_ID);
scrollView.Post(() =>
{
    scrollView.ScrollTo(0, scrollView.Bottom);
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-11
    • 2011-12-11
    • 2020-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-19
    相关资源
    最近更新 更多