gpt4 book ai didi

android - 如何检测ListView结束或开始的淡入淡出边缘?

转载 作者:行者123 更新时间:2023-11-29 17:57:33 26 4
gpt4 key购买 nike

我已经在 StackOverflow 中尝试了很多帖子,但都没有成功。我的要求很简单。我有一个 listView。滚动 listView 时,我想检测 Fading Edge,即当褪色边缘可见时,我想显示 Log massage。如何检测衰落边缘

*更新:我找到了解决方案。这是我的解决方案。*

第 1 步:首先,我扩展了 ListView,如下所示

ManipulateList.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 方法来执行我自己的任务。

第 2 步:“activity_main.xml”声明与我修改后的 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>

第 3 步:我的主要 Activity 的 onCreate 方法如下所示

@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);




}

第 4 步:尽情享受吧!

最佳答案

“Fading Edge”被称为“Overscroll”效果。

查看onOverScroll()方法。

编辑:它不叫 OverScroll。它叫做EdgeEffect .

关于android - 如何检测ListView结束或开始的淡入淡出边缘?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18298909/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com