【发布时间】:2014-09-04 18:50:20
【问题描述】:
在一个 android 应用程序中,我有一个垂直方向的线性布局。此布局包含 2 个子项(listview 和一个 textview)。问题是布局必须仅在列表视图完成滚动时才显示文本视图。请帮我设计布局?
【问题讨论】:
-
其实@Setu 的副本比我的更适合。
标签: android listview layout scrollview
在一个 android 应用程序中,我有一个垂直方向的线性布局。此布局包含 2 个子项(listview 和一个 textview)。问题是布局必须仅在列表视图完成滚动时才显示文本视图。请帮我设计布局?
【问题讨论】:
标签: android listview layout scrollview
您只需要知道列表视图何时位于底部或显示最后一项,然后让您的文本视图可见,这段代码就可以解决问题:
yourListView.setOnScrollListener(this);//The class must implement onscrolllistener
@Override
public void onScroll(AbsListView lw, final int firstVisibleItem,
final int visibleItemCount, final int totalItemCount) {
switch(lw.getId()) {
case android.R.id.list:
// Make your calculation stuff here. You have all your
// needed info from the parameters of this function.
// Sample calculation to determine if the last
// item is fully visible.
final int lastItem = firstVisibleItem + visibleItemCount;
if(lastItem >= totalItemCount) {
if(preLast!=lastItem){ //to avoid multiple calls for last item
Log.d("Last", "Last");
preLast = lastItem;
//Make your text view visible
}
}
}
}
同样重要的是要提及“您不应该在 ScrollView 中包含列表视图。”,它违反了 Android 设计指南,如果您采用这种方法,您可能会做一些非常错误的事情。
希望对你有帮助!
问候!
【讨论】: