简体   繁体   中英

how to get first and last position of textview from horizontal scroll view

friend's

I have a horizontal scrollview with text fields,here i need to get the first and last position of textview when i scrolled it,how can i get the position of textview when i scrolled.and also need to know how to set color for text when i clicked the particular text from this.

sample code....

<HorizontalScrollView android:id="@+id/gv"
        android:layout_width="wrap_content" android:layout_marginTop="0dip"
        android:layout_height="wrap_content" android:background="#ffffff"
        android:scrollbars="none" android:layout_weight="1" android:layout_gravity="center">
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="wrap_content" android:layout_height="wrap_content">

               <TextView android:id="@+id/music2" android:text="Music" android:layout_width="wrap_content"
                android:layout_marginLeft="5dip" android:textSize="15sp" android:layout_height="wrap_content"
                android:background="@drawable/selector" style="@style/FirstText"
                android:gravity="center"/>

                <TextView android:textColor="#000000" android:paddingLeft="10dip"  android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="|"/>

               <TextView android:id="@+id/movies2" android:text="Movies" android:layout_width="wrap_content"
                android:textSize="15sp" android:layout_marginLeft="5dip" android:layout_height="wrap_content"
                android:background="@drawable/selector" style="@style/FirstText"  android:gravity="center"/>

                <TextView android:textColor="#000000" android:paddingLeft="10dip"  android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="|"/>

               <TextView android:id="@+id/interview2" android:text="Interview" android:layout_width="wrap_content"
                android:textSize="15sp" android:layout_marginLeft="5dip" android:layout_height="wrap_content" 
                android:background="@drawable/selector" style="@style/FirstText"  android:gravity="center"/>

                <TextView  android:textColor="#000000" android:paddingLeft="10dip"  android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="|"/>

....

Thanks in advance

您可以使用getScrollY()方法获取y位置...滚动之前/之后以编程方式跟踪位置...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM