I managed to solve this problem using the scroll listener in the list. (checked on 2.1)
Let's say that for each line of the list I have a layout similar to the one below. There is part of the content and part of the header. It doesn't matter what type of view is used for the title or content.
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:background="#FFFFFF"> <ImageView android:id="@+id/content" android:layout_width="fill_parent" android:layout_height="300dp" android:scaleType="centerCrop" android:src="@drawable/pic" android:background="#aaaaff" android:layout_marginTop="40dp"/> <TextView android:id="@+id/header" android:layout_width="fill_parent" android:layout_height="40dp" android:padding="12dp" android:text="Deneme Row" android:textColor="#000000" android:background="#99ffffff"/> </RelativeLayout>
The testing scheme for the action is as follows:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ListView android:id="@+id/list" android:layout_width="fill_parent" android:layout_height="fill_parent" > </ListView> </LinearLayout>
Finally, the code for the activity is given below. Here I had to have an adapter that uses ViewHolder to store the title view, as well as a variable to track the scroll change for each subsequent scroll event (previousTop). This is because offsetTopAndBottom () changes the offset of the view associated with the previous location.
public class TestActivity extends Activity implements AbsListView.OnScrollListener{ ListView list; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); list = (ListView) findViewById(R.id.list); list.setAdapter(new Adapter(this)); list.setOnScrollListener(this); } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
source share