Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android s允许比视图宽(因此可以水平滚动)_Android_Scroll_Textview_Android Scrollview_Scrollable - Fatal编程技术网

Android s允许比视图宽(因此可以水平滚动)

Android s允许比视图宽(因此可以水平滚动),android,scroll,textview,android-scrollview,scrollable,Android,Scroll,Textview,Android Scrollview,Scrollable,可以是布尔值,例如“真”或“假” Prigramacaly-setHorizontallyScrolling(布尔值)尝试以下方法: android:scrollbars = "vertical" 在kotlin中,用于使textview可滚动 myTextView.movementMethod= ScrollingMovementMethod() 并在xml中添加此属性 android:scrollbars = "vertical" 您现在可以滚动它。对于可垂直或水平滚动的文本,

可以是布尔值,例如“真”或“假”

Prigramacaly-
setHorizontallyScrolling(布尔值)

尝试以下方法:

android:scrollbars = "vertical"

在kotlin中,用于使textview可滚动

myTextView.movementMethod= ScrollingMovementMethod()
并在xml中添加此属性

    android:scrollbars = "vertical"
您现在可以滚动它。

对于可垂直或水平滚动的文本,请查看其他一些答案帮助,但我需要能够双向滚动

最终工作的是一个滚动视图,其中包含一个水平滚动视图,HSV中包含一个文本视图。这是非常顺利,可以很容易地去一边到另一边或顶部到底部在一次轻扫。它也只允许一次向一个方向滚动,所以在向上或向下滚动时不会出现左右跳跃的情况

禁用编辑和光标的EditText可以工作,但感觉很糟糕。每次尝试滚动都会移动光标,即使在一个100行的文件中,也需要多次滑动才能从上到下或从一侧到另一侧滚动


使用
setHorizontallyScrolling(true)
可以工作,但是没有类似的方法允许垂直滚动,而且据我所知,它在滚动视图内部不起作用(只是学习,可能是错误的)。

如果使用Kotlin,那么: XML

 <TextView
            android:id="@+id/tvMore"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:maxLines="3"
            android:scrollbars="vertical" />


但是肯定
maxLines
要求您输入任意数字;这不是每个屏幕大小和字体大小都适用的东西吗?我发现用
ScrollView
来包装它更简单,这意味着我不必再添加任何XML属性或代码(比如设置移动方法)。@Christopher,ScrollView也需要“android:layout\u height”。@Regex:是的。您可以让
ScrollView
占据所需的空间(例如通过
android:fillViewport
属性),也可以设置所需的特定大小。不应使用
maxLines
设置UI元素的大小,因此这不是解决方案。您不需要定义maxLines。仅此而已。为了澄清大家对“平滑”滚动的看法:如果你使用这种方法,滚动实际上是“平滑的”(你可以逐像素滚动),但它不是动态的。一旦你移开手指,它就会立即停止滚动——没有任何滚动。这对于现代用户界面来说是不可接受的,所以我将编辑答案,以确保其他人不会在这个“解决方案”上浪费时间。有没有办法用XML设置这个属性?我想知道他们为什么会忽略这个选项。它可以工作,但在滚动后有没有办法刷新它?我的意思是,在滚动文本视图之后,我将更改其上的文本,但即使不需要,它的位置仍保持滚动。它的b原因以前我应用了滚动…没有滚动条,与
ScrollView
方法相比,滚动是笨拙的。使用
StringBuilder
而不是
String
。。。你拥有的东西有点浪费。这可以工作,但滚动不顺畅。谢谢,但仍然有效。为什么还要写这个?这是一个几乎相同但不太正确的答案版本,在你写它之前已经发布了6个多月。很容易,这是最好和最合适的答案,特别是考虑到EditText是一个TextView子类,问题是如何使TextView可滚动,而不是如何解决这个问题。如果可以的话,我会投两次赞成票:)@JustinBuser完全不同意这纯属偶然,而且也不能保证它在未来的Android版本中会起作用。如果您想要滚动,请使用Android提供的滚动工具
ScrollView
是正确的方式。@Madbreaks它并没有什么“意外”,EditText是一个文本视图,带有一些添加的方法和覆盖,专门为适应不同长度的文本而定制。尤其是EditText重写TextView getDefaultMovementMethod函数的返回值。默认实现返回NULL,EditText基本上执行所有其他答案所建议的相同操作。就使用Android提供的工具而言,EditText类比这些答案中的任何其他方法都不太可能被弃用。@JustinBuser我的问题是,您依赖于EditText的默认行为,这就是我的意思,以后可能会发生很大的变化(完全不是说EditText会被弃用)。你可以这么说,但同样,我们的想法是使用适合手头任务的组件和功能。ScrollView明确设计为包含滚动。我总是尝试,并且总是建议其他人使用正确的工具来完成这项工作。对于任何给定的编程问题,几乎总是有多种方法。无论如何,谢谢对于深思熟虑的响应。dude,tablescroller是一个由中处理的XML中的id属性标识的视图。你只要试试它。它会很好。它的工作原理是我。启用蓝色动画。最好的答案是在这里。无需使用
mTextView.getBottom()
,只需使用方法
mScrollView.fullScroll即可(View.FOCUS_DOWN)
,因为它是ScrollView API的一部分。有关更多信息,请参阅和。Android警告说,
LinearLayout
ScrollView
在本例中可能没有用(我完全删除了
LinearLayout
)。它还警告说,对于
TextView
,它应该是
android:layout\u height=“wrap\u content”
以匹配
滚动视图
。这些警告可能是由于此答案发布后的3年时间造成的。无论如何,此答案支持平滑滚动和轻弹…+1在xml文件中的
滚动视图
上方添加
将处理这些警告。“pro提示”在Android API 9级中,这对我不起作用。文本视图在添加文本后会一直滚动到顶部。使用接受的应答应用程序,这种方法要好得多
<?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">

    <ScrollView
        android:id="@+id/SCROLLER_ID"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scrollbars="vertical"
        android:fillViewport="true">

        <TextView
            android:id="@+id/TEXT_STATUS_ID"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1.0"/>
    </ScrollView>
</LinearLayout>
mTextStatus = (TextView) findViewById(R.id.TEXT_STATUS_ID);
mScrollView = (ScrollView) findViewById(R.id.SCROLLER_ID);

private void scrollToBottom()
{
    mScrollView.post(new Runnable()
    {
        public void run()
        {
            mScrollView.smoothScrollTo(0, mTextStatus.getBottom());
        }
    });
}
android:background="@null"
android:editable="false"
android:cursorVisible="false"
<TextView
    android:id="@+id/TEXT"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:text="@string/long_text"/>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent">

    <ScrollView
        android:id="@+id/ScrollView01"
        android:layout_height="150px"
        android:layout_width="fill_parent">

        <TextView
            android:id="@+id/TEXT"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="@string/long_text"/>

    </ScrollView>
</RelativeLayout>
((ScrollView) findViewById(R.id.TableScroller)).fullScroll(View.FOCUS_DOWN);
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.yourLayout);
    (TextView)findViewById(R.id.yourTextViewId).setMovementMethod(ArrowKeyMovementMethod.getInstance());
}
ScrollView scroller = new ScrollView(this);
TextView tv = new TextView(this);
tv.setText(R.string.my_text);
scroller.addView(tv);
public class AutoScrollableTextView extends TextView {

    public AutoScrollableTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        setEllipsize(TruncateAt.MARQUEE);
        setMarqueeRepeatLimit(-1);
        setSingleLine();
        setHorizontallyScrolling(true);
    }

    public AutoScrollableTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        setEllipsize(TruncateAt.MARQUEE);
        setMarqueeRepeatLimit(-1);
        setSingleLine();
        setHorizontallyScrolling(true);
    }

    public AutoScrollableTextView(Context context) {
        super(context);
        setEllipsize(TruncateAt.MARQUEE);
        setMarqueeRepeatLimit(-1);
        setSingleLine();
        setHorizontallyScrolling(true);
    }

    @Override
    protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
        if(focused)
            super.onFocusChanged(focused, direction, previouslyFocusedRect);
    }

    @Override
    public void onWindowFocusChanged(boolean focused) {
        if(focused)
            super.onWindowFocusChanged(focused);
    }

    @Override
    public boolean isFocused() {
        return true;
    }
}
 <com.yourpackagename.AutoScrollableTextView
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:text="This is very very long text to be scrolled"
 />
if ((mTextStatus.getMeasuredHeight() - mScrollView.getScrollY()) <=
        (mScrollView.getHeight() + mTextStatus.getLineHeight())) {
    scrollToBottom();
}
TextView textview= (TextView) findViewById(R.id.your_textview_id);
textview.setMovementMethod(new ScrollingMovementMethod());
android:ellipsize="marquee"
android:focusable="false"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="To Make An textView Scrollable Inside The TextView Using Marquee"
textview.setSelected(true);
textView.setMovementMethod(new ScrollingMovementMethod());
android:scrollbars="vertical"
textView.setMovementMethod(new ScrollingMovementMethod());
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.TextView;

public class PerfectScrollableTextView extends TextView {

    public PerfectScrollableTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        setVerticalScrollBarEnabled(true);
        setHorizontallyScrolling(false);
    }

    public PerfectScrollableTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        setVerticalScrollBarEnabled(true);
        setHorizontallyScrolling(false);
    }

    public PerfectScrollableTextView(Context context) {
        super(context);
        setVerticalScrollBarEnabled(true);
        setHorizontallyScrolling(false);
    }

    @Override
    protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
        if(focused)
            super.onFocusChanged(focused, direction, previouslyFocusedRect);
    }

    @Override
    public void onWindowFocusChanged(boolean focused) {
        if(focused)
            super.onWindowFocusChanged(focused);
    }

    @Override
    public boolean isFocused() {
        return true;
    }
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    tools:context="com.mbh.usbcom.MainActivity">
    <TextView
        android:id="@+id/tv_log"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="vertical"
        android:text="Log:" />
</RelativeLayout>
tv_log = (TextView) findViewById(R.id.tv_log);
tv_log.setMovementMethod(new ScrollingMovementMethod());
    android:gravity="bottom"
    tv_log.append("\n" + text);
android:Maxlines="AN_INTEGER"`
android:scrollbars = "vertical"
textview.setMovementMethod(new ScrollingMovementMethod());
<TextView android:maxLines="1" 
          android:ellipsize="marquee"
          android:scrollHorizontally="true"/>
tv.setSelected(true);
tv.setHorizontallyScrolling(true); 
<TextView  
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:maxLines = "AN_INTEGER"
    android:scrollbars = "vertical"
/>
YOUR_TEXTVIEW.setMovementMethod(new ScrollingMovementMethod());
android:scrollbars="vertical"
android:scrollIndicators="right|end"
<TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scrollbars="vertical"
    android:maxLines="5" // any number of max line here.
    />
scrollView.setOnTouchListener(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {

                description.getParent().requestDisallowInterceptTouchEvent(false);

                return false;
            }
        });

        description.setOnTouchListener(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {

                description.getParent().requestDisallowInterceptTouchEvent(true);

                return false;
            }
        });
<EditText
     android:id="@+id/description_text_question"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:background="@null"
     android:editable="false"
     android:cursorVisible="false"
     android:maxLines="6"/>
android:scrollbars = "vertical"
myTextView.movementMethod= ScrollingMovementMethod()
    android:scrollbars = "vertical"
yourtextView.setMovementMethod(new ScrollingMovementMethod());
 <TextView
            android:id="@+id/tvMore"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:maxLines="3"
            android:scrollbars="vertical" />
tvMore.movementMethod = ScrollingMovementMethod()