有人可以帮忙吗?我试图让我的Android屏幕自动向下滚动,因为更多文本被添加到TextView。这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
namespace GameEngine
{
[Activity(Label = "nameScreen")]
public class nameScreen : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
Window.RequestFeature(WindowFeatures.NoTitle);
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.enterName);
TextView tv = FindViewById<TextView>(Resource.Id.Text);
tv.MovementMethod = new Android.Text.Method.ScrollingMovementMethod();
FindViewById<TextView>(Resource.Id.Text).Text = "Hi";
Button send = FindViewById<Button>(Resource.Id.send);
tv.setMovementMethod(new ScrollingMovementMethod());
底部的tv.setMovementMethod结果:
'TextView' does not contain a definition for 'setMovementMethod'
and no extension method 'setMovementMethod' accepting a first
argument of type 'Textview' could be found (are you missing a
using directive or and assembly reference?)
这是在C#中的Xamarin。
AXML代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:text="Text"
android:layout_width="match_parent"
android:focusable="true"
android:gravity="bottom"
android:focusableInTouchMode="true"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:layout_height="455.5dp"
android:id="@+id/Text"
android:scrollbars="vertical"/>
<EditText
android:inputType="textPersonName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/nameTB" />
<Button
android:text="Send"
android:layout_width="379.5dp"
android:layout_height="wrap_content"
android:id="@+id/send" />
</LinearLayout>
谢谢!
答案 0 :(得分:0)
一般来说,Java中的set *和get *方法被映射为带有getter和setter的标准C#属性。因此,setMovementMethod
和getMovementMethod
都会被公开为MovementMethod
属性。
答案 1 :(得分:0)
在C#中,您应该按照以下方式执行此操作
yourTextView.MovementMethod = new ScrollingMovementMethod() ;