Android - 同时滚动多个文本视图?

时间:2014-11-22 03:53:11

标签: android android-layout

我希望只要滚动一个TextView(垂直滚动),就可以同时滚动所有三个textView。

(注意我正在(可扩展ListView)的Listview中进行滚动)

目前如果我只滚动一个TextView,那么TextView会滚动,其余两个不滚动,我的代码如下所示

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/recentrelative"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/blacker"
    android:orientation="vertical"
    android:padding="16dp" >

    <RelativeLayout
        android:id="@+id/recentrelative"
        android:layout_width="match_parent"
        android:layout_height="140dp"
        android:layout_marginRight="10dp"
        android:background="@color/blacker"
        android:orientation="vertical" >

            <LinearLayout
                android:id="@+id/linearLayout1"
                android:layout_width="300dp"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:weightSum="1" >


                <TextView
                    android:id="@+id/recentitems"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="10dp"
                    android:layout_marginRight="20dp"
                    android:layout_marginTop="10dp"
                    android:layout_weight="0.61"
                    android:lineSpacingExtra="11dp"
                    android:maxLines="20"
                    android:scrollHorizontally="true"
                    android:scrollbars="vertical"
                    android:text="Kabab family pack with masala"
                    android:textColor="@color/white"
                    android:textSize="12dip" />

                <TextView
                    android:id="@+id/recentquantity"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="10dp"
                    android:layout_marginRight="12dp"
                    android:layout_marginTop="10dp"
                    android:layout_weight="0.30"
                    android:lineSpacingExtra="11dp"
                    android:maxLines="20"
                    android:scrollHorizontally="true"
                    android:scrollbars="vertical"
                    android:text="10"
                    android:textColor="@color/white"
                    android:textSize="12dip" />

                <TextView
                    android:id="@+id/recentprice"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="10dp"
                    android:layout_marginRight="12dp"
                    android:layout_marginTop="10dp"
                    android:layout_weight="0.30"
                    android:lineSpacingExtra="11dp"
                    android:maxLines="20"
                    android:scrollHorizontally="true"
                    android:scrollbars="vertical"
                    android:text="TextView"
                    android:textColor="@color/white"
                    android:textSize="12dip" />

            </LinearLayout>

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/imageView1"
            android:layout_toRightOf="@+id/linearLayout1"
            android:text="Medium Text"
            android:textSize="13dip" />

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="90px"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_toRightOf="@+id/horizontalScrollView1"
            android:src="@drawable/hearts" />
    </RelativeLayout>

    </RelativeLayout>

滚动我正在使用以下代码:

    TextView txtListname= ( TextView ) convertView.findViewById( R.id.recentitems);
            TextView txtRecentQuantity = ( TextView ) convertView.findViewById( R.id.recentquantity );
            TextView txtRecentPrice = ( TextView ) convertView.findViewById( R.id.recentprice );



txtRecentQuantity.setMovementMethod( new ScrollingMovementMethod() );
        txtListname.setMovementMethod( new ScrollingMovementMethod() );
        txtRecentPrice.setMovementMethod( new ScrollingMovementMethod() );


OnTouchListener listener = new 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;
            }
        };



        txtRecentQuantity.setOnTouchListener( listener );
        txtRecentQuantity.setText( childquantity );
        txtListname.setOnTouchListener( listener );
        txtListname.setText( childitems );
        txtRecentPrice.setOnTouchListener( listener );
        txtRecentPrice.setText( childprice );

0 个答案:

没有答案