android可滚动textview无法在scrollview中工作

时间:2014-03-18 06:54:02

标签: android scroll textview scrollview

我正在开发1个应用程序,因为我需要1 scrollview在此scrollview中我需要放置滚动textview / webview(必须显示一些静态字符串)但必须在scrollview内滚动但不能正常工作< / p>

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="@color/white" >  
    <ScrollView
            android:id="@+id/scrollView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/img_view_flag"
            android:layout_marginTop="17dp" 
            android:paddingBottom="20dip">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" >



                    <TextView
                        android:id="@+id/tv_desc"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_below="@+id/rel_layout"
                        android:layout_marginTop="15dp"
                        android:maxLines="2"
                        android:scrollbars="vertical"
                        android:text="Medium Text"
                        android:paddingBottom="10dip"
                         android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@color/black" />
     </LinearLayout>
        </ScrollView>

    </RelativeLayout>

在myjava文件中,我已经完成了......

scrollView1 = (ScrollView) findViewById(R.id.scrollView1);
    // scrollView2 = (ScrollView) findViewById(R.id.scrollView2);
    tv = (TextView) findViewById(R.id.tv_desc);
    tv.setText("this is 1\n"+"this is 2"+"\n this ix 3\n"+"this is 4\n\n"+"this is 5\n" );

    scrollView1.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View arg0, MotionEvent arg1) {
            // TODO Auto-generated method stub Log.v("PARENT",
            // "PARENT TOUCH");
            Log.v("PARENT", "PARENT TOUCH");
            findViewById(R.id.tv_desc).getParent()
                    .requestDisallowInterceptTouchEvent(false);
            return false;
        }
    });
    tv.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View arg0, MotionEvent arg1) {
            Log.v("TextView", "CHILD TOUCH");
            arg0.getParent().requestDisallowInterceptTouchEvent(true);
            return false;
        }
    });

但不为我工作......我错过了什么或错过了什么?

2 个答案:

答案 0 :(得分:5)

您必须在代码中使用以下行来使textview可滚动..

yourTextView.setMovementMethod(new ScrollingMovementMethod())

答案 1 :(得分:-1)

找到解决方案。

在OnCreate()函数的末尾添加以下行

    scrollView.setOnTouchListener(new View.OnTouchListener() {

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

            textView.getParent().requestDisallowInterceptTouchEvent(false);

            return false;
        }
    });

    textView.setOnTouchListener(new View.OnTouchListener() {

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

            textView.getParent().requestDisallowInterceptTouchEvent(true);

            return false;
        }
    });