我在这里尝试了很多帖子,StackOverflow
但没有运气。我的要求很简单。我有一个listView
. 滚动 时listView
,我想检测Fading Edge
,即当褪色边缘可见时,我想显示日志按摩。我怎样才能检测到Fading Edge
?
*更新:我找到了解决方案。这是我的解决方案。*
STEP 1: First I extended the ListView as shown below
操作列表.java
public class ManipulateList extends ListView {
public ManipulateList(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public ManipulateList(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public ManipulateList(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
@Override
protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX,
boolean clampedY) {
// TODO Auto-generated method stub
Log.d("***", "Over Scrolling: Fading Edge NOW Visible");
super.onOverScrolled(scrollX, scrollY, clampedX, clampedY);
}
}
在这里你可以看到,我已经覆盖了onOverScrolled
在这里执行我自己的任务的方法。
Step 2: "activity_main.xml" declaration with my modified listview
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<com.example.customlist.ManipulateList
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</com.example.customlist.ManipulateList>
</RelativeLayout>
STEP 3: My main activity's onCreate Method shown Below
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ManipulateList listView = (ManipulateList) findViewById(R.id.listView1);
String[] swName = new String[] {"a", "b","c",
"d", "e","f",
"g", "h","i",
"j", "k","l",
"m", "n","o",
"p", "q","r",
"s", "t","u",
"v", "w","x",
"y","z","a","b",
"c","d","e","f"
};
ArrayAdapter<String> swGAA = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, swName);
listView.setAdapter(swGAA);
}
STEP 4: ENJOY!