public class TwoHeaderListView extends FrameLayout{
private static final String TAG = "TwoHeaderListView";
ImageView header1;
ImageView header2;
ListView listview;
ImageView fixheader;
public TwoHeaderListView(Context context) {
super(context);
init(context);
}
private void init(Context ctx){
//固定头其实是另外的浮在上层的一个view和header2张的一样的一个view。
fixheader = new ImageView(ctx);
fixheader.setBackgroundColor(Color.RED);
fixheader.setVisibility(View.GONE);
header1 = new ImageView(ctx);
header2 = new ImageView(ctx);
header1.setBackgroundColor(Color.GRAY);
header2.setBackgroundColor(Color.RED);
AbsListView.LayoutParams lp2 = new AbsListView.LayoutParams(LayoutParams.FILL_PARENT, 50);
header2.setLayoutParams(lp2);
header1.setLayoutParams(lp2);
listview = new ListView(ctx);
listview.setOnScrollListener(new OnScrollListener(){
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
if (firstVisibleItem > 0){
fixheader.setVisibility(View.VISIBLE);//设置成可见
fixheader.bringToFront();
} else{
fixheader.setVisibility(View.GONE);
}
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
});
this.addView(listview);
LayoutParams lp = new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, 50);
this.addView(fixheader, lp);
LinkedList<String> mListItems = new LinkedList<String>();
mListItems.addAll(Arrays.asList(mStrings));
adapter = new ArrayAdapter<String>(ctx,
android.R.layout.simple_list_item_1, mListItems);
listview.addHeaderView(header1);
listview.addHeaderView(header2);
listview.setAdapter(adapter);
}
ArrayAdapter<String> adapter = null;
private String[] mStrings = {
"Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam",
"Abondance", "Ackawi", "Acorn", "Adelost", "Affidelice au Chablis",
"Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre",
"Allgauer Emmentaler"};
}
ListView特效1
最新推荐文章于 2024-12-17 07:19:40 发布
本文介绍了一种自定义的Android列表视图组件——双头部列表视图的实现方法。该组件包含两个头部图片视图,并随滚动显示或隐藏一个浮动头部。文中详细展示了如何通过Java代码创建并初始化视图组件,设置监听器来响应滚动事件,以及添加数据适配器以填充列表内容。
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
Anything-LLM
AI应用
AnythingLLM是一个全栈应用程序,可以使用商用或开源的LLM/嵌入器/语义向量数据库模型,帮助用户在本地或云端搭建个性化的聊天机器人系统,且无需复杂设置

210

被折叠的 条评论
为什么被折叠?



