滚动到布局底部
Scroll to bottom of layout
我正在尝试滚动到布局底部。我有这段代码,但它不起作用
ScrollView scrollView = view.FindViewById<ScrollView>(Resource.Id.scrollViewHelper);
scrollView.FullScroll(FocusSearchDirection.Down);
一种简单的方法是创建一个基于 Action 的 runnable,将 Action 作为参数传递给 runnable。
您可以参考以下代码:
scrollView = FindViewById<ScrollView>(Resource.Id.scrollView1);
var runnable = new MyRunnable(async () =>
{
// Do whatever you need to do, including capturing of local vars, app/activity context, etc.
await Task.Delay(500);
scrollView.FullScroll(FocusSearchDirection.Down);
});
runnable.Run();
代码 class MyRunnable
public class MyRunnable : Java.Lang.Object, Java.Lang.IRunnable
{
readonly WeakReference<Action> actionRef;
public MyRunnable(Action action)
{
actionRef = new WeakReference<Action>(action);
}
public void Run()
{
actionRef.TryGetTarget(out Action action);
action?.Invoke();
}
}
我正在尝试滚动到布局底部。我有这段代码,但它不起作用
ScrollView scrollView = view.FindViewById<ScrollView>(Resource.Id.scrollViewHelper);
scrollView.FullScroll(FocusSearchDirection.Down);
一种简单的方法是创建一个基于 Action 的 runnable,将 Action 作为参数传递给 runnable。 您可以参考以下代码:
scrollView = FindViewById<ScrollView>(Resource.Id.scrollView1);
var runnable = new MyRunnable(async () =>
{
// Do whatever you need to do, including capturing of local vars, app/activity context, etc.
await Task.Delay(500);
scrollView.FullScroll(FocusSearchDirection.Down);
});
runnable.Run();
代码 class MyRunnable
public class MyRunnable : Java.Lang.Object, Java.Lang.IRunnable
{
readonly WeakReference<Action> actionRef;
public MyRunnable(Action action)
{
actionRef = new WeakReference<Action>(action);
}
public void Run()
{
actionRef.TryGetTarget(out Action action);
action?.Invoke();
}
}