Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.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 使多行文本视图在ListView中可滚动_Android_Listview_Scroll - Fatal编程技术网

Android 使多行文本视图在ListView中可滚动

Android 使多行文本视图在ListView中可滚动,android,listview,scroll,Android,Listview,Scroll,我正在尝试使我的多行文本视图在listview中可滚动,但失败。 以下是我的一些代码: myCommentTextView.setMovementMethod(new ScrollingMovementMethod());` <TextView android:id="@+id/textViewComment" android:layout_width="match_parent" android:layout_height="60dp

我正在尝试使我的多行文本视图在listview中可滚动,但失败。 以下是我的一些代码:

 myCommentTextView.setMovementMethod(new ScrollingMovementMethod());`

 <TextView
        android:id="@+id/textViewComment"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:scrollbarAlwaysDrawHorizontalTrack="false"
        android:scrollbarAlwaysDrawVerticalTrack="true"
        android:overScrollMode="always"
        android:scrollbarStyle="insideOverlay"
        android:scrollbars="vertical"
        android:text="Comment"
        android:textSize="14sp"
        android:typeface="normal" />
我试图创建一个这样的自定义类,但android studio在
列表的第行显示红色下划线
(无法解析方法)和
扩展TextView
(应扩展android.support.v7.widget.appcompatTextView)

这是我的班级:

import android.content.Context;
import android.view.MotionEvent;
import android.widget.TextView;    
import java.util.List;


    public class MyTextView extends TextView {

        public MyTextView(Context context)
        {
            super(context);
            // TODO Auto-generated constructor stub
        }
        public boolean dispatchTouchEvent(MotionEvent event)
        {
            boolean ret;
            ret = super.dispatchTouchEvent(event);
            if(ret)
            {
                List.requestDisallowInterceptTouchEvent(true);

            }
            return ret;
        }

    }
我可以将textview更改为appCompatTextView,尽管我不明白为什么,因为从源代码看,这似乎没问题,因为这是公认的答案。但是,最重要的代码仍然是List.requestDisallowWinterCeptTouchEvent(true)将保留错误


如何解决这个问题

我找到了答案,RequestDisallowWinterCeptTouchEvent确实是这里的关键

 View.OnTouchListener listener = new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                boolean isLarger;

                isLarger = ((TextView) v).getLineCount()
                        * ((TextView) v).getLineHeight() > v.getHeight();
                if (event.getAction() == MotionEvent.ACTION_MOVE
                        && isLarger) {
                    v.getParent().requestDisallowInterceptTouchEvent(true);

                } else {
                    v.getParent().requestDisallowInterceptTouchEvent(false);

                }
                return false;
            }
        };

        holder.comment.setOnTouchListener(listener);

尝试“android:maxLines=“5”//which you needed”。尝试过但没有成功,我认为问题在于listview正在接管focus/touch侦听器。因此,即使我触摸并滚动textview,整个列表也会滚动
 View.OnTouchListener listener = new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                boolean isLarger;

                isLarger = ((TextView) v).getLineCount()
                        * ((TextView) v).getLineHeight() > v.getHeight();
                if (event.getAction() == MotionEvent.ACTION_MOVE
                        && isLarger) {
                    v.getParent().requestDisallowInterceptTouchEvent(true);

                } else {
                    v.getParent().requestDisallowInterceptTouchEvent(false);

                }
                return false;
            }
        };

        holder.comment.setOnTouchListener(listener);