开发者

How to keep entire row highlighted (with HorizontalScrollView)

开发者 https://www.devze.com 2023-02-01 21:51 出处:网络
I have a ListView that has rows with basically 2 TextViews each. But, one of these textviews is inside a HorizontalScrollView.

I have a ListView that has rows with basically 2 TextViews each. But, one of these textviews is inside a HorizontalScrollView.

I desire the following behavior IN TOUCH MODE:

1) When the user presses any of TextViews, the ENTIRE row must be highlighted. He can scroll left/right the first textview, but the entire row must remain highlighted.

2) After user realease the "press", the row MUST STAY highlighted, until the user presses another row or scrolls up/down the list.

Thanks in advance.

Row layout:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
>
    <HorizontalScrollView
        android:id="@+id/frmclientes_listview_linha_scrollView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center_vertical"
        android:fillViewport="true"
        android:scrollbars="none"
        android:scrollbarAlwaysDrawHorizontalTrack="false"
        android:scrollbarAlwaysDrawVerticalTrack="false"
        android:fadingEdge="horizontal"
        android:fadingEdgeLength="30sp"
    >
        <TextView
            android:id="@+id/frmclientes_listview_line_firstline"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_alignParentTop="true"
            android:ellipsize="marquee"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:gravity="center_vertical"
            android:focusable="false"
            android:lines="1" />
    </Horiz开发者_开发知识库ontalScrollView>

    <TextView
        android:id="@+id/frmclientes_listview_line_secondline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_below="@+id/frmclientes_listview_linha_scrollView1"
        android:ellipsize="marquee"
        android:gravity="center_vertical"
        android:lines="1"
        android:textAppearance="?android:attr/textAppearanceSmall" />

</RelativeLayout>


You should be able to override HorizontalScrollView.draw()

public class HorizontalScrollViewHighlight extends HorizontalScrollView {
    public boolean isHighlighted = false;
    public HorizontalScrollViewHighlight(Context context) {
        super(context, null);
    }
    @Override
    public void draw(Canvas canvas) {
        super.draw(canvas);
        if (isHighlighted)
            // highlight code
        else
            // non-highlighted code
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号