Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
335 views
in Technique[技术] by (71.8m points)

android - TextView is not clickable inside scrollview in listview?

My inflate layout:-

<FrameLayout
    android:layout_width="100dip"
    android:layout_height="100dip"
    android:gravity="center"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/UserImageView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/no_image"
        android:gravity="center_horizontal|bottom"
        android:orientation="vertical"
        android:scaleType="fitXY" >
    </ImageView>

    <TextView
        android:id="@+id/UserTitleTextView"
        android:layout_width="fill_parent"
        android:layout_height="25dip"
        android:layout_gravity="bottom"
        android:background="@android:color/transparent"
        android:gravity="center_vertical"
        android:paddingLeft="5dip"
        android:paddingRight="28dip"
        android:singleLine="true"
        android:text=""
        android:textColor="@android:color/white"
        android:textSize="16sp" />

    <ImageView
        android:id="@+id/UserRecentActivityIcon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right"
        android:layout_marginBottom="10dip"
        android:layout_marginRight="8dip"
        android:gravity="bottom|right" />

    <ImageView
        android:id="@+id/redDotActivityIconInflateGroupDetail02"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right"
        android:layout_marginBottom="30dip"
        android:layout_marginRight="4dip"
        android:gravity="bottom|right"
        android:src="@drawable/red_dot_icon" />
</FrameLayout>

<RelativeLayout
    android:id="@+id/RelativeLayoutMain"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginBottom="5dip"
    android:layout_marginLeft="10dip"
    android:layout_marginTop="5dip"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/activityTitleTextViewGroupDetail"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingRight="5dip"
        android:singleLine="true"
        android:text=""
        android:textColor="@android:color/white"
        android:textSize="15sp" />

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/thumbUrlImageView"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_alignParentRight="true" >
        </ImageView>
    </RelativeLayout>

    <ImageView
        android:id="@+id/ArrowImageView"
        android:layout_width="15dip"
        android:layout_height="20dip"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:background="@drawable/arrow1" />

    <ScrollView
        android:id="@+id/ScrollMain"
        android:fillViewport="true"
        android:clickable="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/activityTitleTextViewGroupDetail"
        android:layout_marginTop="3dip" >

        <com.example.app.EllipsizingTextView
            android:id="@+id/messageTextViewGroupDetail"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:paddingRight="10dip"
            android:text=""
            android:textColor="@android:color/white"
            android:textSize="14.5sp" />
    </ScrollView>

    <TextView
        android:id="@+id/StartDateTextViewGroupDetail02"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/ScrollMain"
        android:layout_marginRight="20dip"
        android:layout_marginTop="5dip"
        android:text=""
        android:textColor="@android:color/white"
        android:textSize="12sp" />

    <TextView
        android:id="@+id/dateTextViewGroupDetail"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_below="@+id/StartDateTextViewGroupDetail02"
        android:text=""
        android:textColor="@android:color/white"
        android:textSize="12sp" />
</RelativeLayout>

please find attaced snapshotenter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Basically in Android, nested scroll-able components are not recommended, but you can use below snippet ::

textView.setOnTouchListener(new ListView.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            int action = event.getAction();

            switch (action) {
            case MotionEvent.ACTION_DOWN:
                // Disallow ScrollView to intercept touch events.
                v.getParent().getParent().getParent()
                        .requestDisallowInterceptTouchEvent(true);
                break;
            case MotionEvent.ACTION_UP:
                // Allow ScrollView to intercept touch events.
                v.getParent().getParent()
                        .requestDisallowInterceptTouchEvent(false);

                    break;
            }
            return true;
        }
    });

And then put, setOnClickListener for the same textView, then textview be scrollable also be clicable.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...