正好,今天项目中需要,先写了个demo,给大家参考参考、

先上图,需要的自己,看看具体的代码实现步骤

大概说一下实现步骤:

1.布局中先用 scrollview 包裹 LinearLayout

  <ScrollView
android:id="@+id/scrollview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/relativeLayout1"
android:fadingEdge="none"
android:scrollbars="vertical"> <LinearLayout
android:id="@+id/linearlayout"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
</LinearLayout>
</ScrollView>

2.具体实现代码

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ScrollView;
import android.widget.TextView; import java.util.ArrayList;
import java.util.List; public class SearchUserContentActivity extends BaseActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search_user_content); initView(); addUserListview(); addContentListview();
}
ScrollView scrollView;
LinearLayout all;
private void initView() {
LayoutInflater inflater = LayoutInflater.from(this);
//LinearLayout linearLayout = (LinearLayout) inflater.inflate(R.layout.main, null);
//layout_topic = (LinearLayout) linearLayout.findViewById(R.id.linearlayout);
all = (LinearLayout) findViewById(R.id.linearlayout);
scrollView = (ScrollView) findViewById(R.id.scrollview);
} private void addUserListview( ){
TextView textView = new TextView(this);
textView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
textView.setText("第一个ListView");
textView.setGravity(Gravity.CENTER);
textView.setTextSize(18);
textView.setTextColor(Color.BLACK);
all.addView(textView); ArrayList arraylist = new ArrayList(); // 生成动态数组
for (int i = 1; i <= 10; i ++) {
arraylist.add( "第一个测试" + i );
} ListViewAdapter listViewAdapter = new ListViewAdapter(this, arraylist);
ListView listView = new ListView(this);
int height = arraylist.size() * 50;
listView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, height));
listView.setDividerHeight(1); listView.setAdapter(listViewAdapter);
all.addView(listView);
} private void addContentListview( ){
TextView textView = new TextView(this);
textView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
textView.setText("第二个ListView");
textView.setGravity(Gravity.CENTER);;
textView.setTextSize(18);
textView.setTextColor(Color.BLACK);
all.addView(textView); ArrayList arraylist = new ArrayList(); // 生成动态数组
for (int i = 11; i <= 20; i ++) {
arraylist.add( "第二个测试" + i );
}
ListViewAdapter listViewAdapter = new ListViewAdapter(this, arraylist); ListView listView = new ListView(this);
int height = arraylist.size() * 50;
listView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, height));
listView.setDividerHeight(1); listView.setAdapter(listViewAdapter);
all.addView(listView);
} class ListViewAdapter extends android.widget.BaseAdapter {
Context context;
List<String> datas; public ListViewAdapter(Context _context,
List<String> relativesList) {
this.datas = relativesList;
this.context = _context;
} @Override
public int getCount() {
return datas.size();
} @Override
public Object getItem(int position) {
return position;
} @Override
public long getItemId(int position) {
return position;
}
public final class ViewHolder {
public TextView name;//昵称
}
@SuppressLint("InflateParams")
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if(convertView == null) {
holder = new ViewHolder();
convertView = LayoutInflater.from(context).inflate(R.layout.item_discovery_search_user, null);
holder.name = (TextView) convertView.findViewById(R.id.name);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.name.setText(datas.get(position));
return convertView;
} }
}

Android 多个listview的实现的更多相关文章

  1. Android 中关于ListView分割线的设置

    今天发现许多App上的listview的item之间的分割线都只显示了右边一部分,而左边的那一半则没有,第一反应则是给分割线设置一张背景图片就ok了: android:divider="@m ...

  2. Android—自定义控件实现ListView下拉刷新

    这篇博客为大家介绍一个android常见的功能——ListView下拉刷新(参考自他人博客,网址忘记了,阅读他的代码自己理解注释的,希望能帮助到大家): 首先下拉未松手时候手机显示这样的界面: 下面的 ...

  3. Android开发学习——ListView+BaseAdapter的使用

    ListView 就是用来显示一行一行的条目的MVC结构 * M:model模型层,要显示的数据           ----people集合 * V:view视图层,用户看到的界面          ...

  4. Android 如何在 ListView 中更新 ProgressBar 进度

    =======================ListView原理============================== Android 的 ListView 的原理打个简单的比喻就是: 演员演 ...

  5. [Android Pro] android控件ListView顶部或者底部也显示分割线

    reference to  :  http://blog.csdn.net/lovexieyuan520/article/details/50846569 在默认的Android控件ListView在 ...

  6. android studio中ListView与SQLite的结合使用

    Da.java public class Db extends SQLiteOpenHelper { public Db(Context context) { super(context, " ...

  7. Android学习笔记——ListView

    该工程的功能是实现在一个activity中显示一个列表 以下代码是MainActivity.java中的代码 package com.example.listview; import java.uti ...

  8. Android课程---关于ListView列表视图的学习

    activity_ui3.xml <?xml version="1.0" encoding="utf-8"?> <ListView xmlns ...

  9. Android UI组件----ListView列表控件详解

    [声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/3 ...

  10. Android 长按Listview显示CheckBox,实现批量删除。

    ListView实现的列表,如果是可编辑,可删除的,一般都要提供批量删除功能,否则的话,一项一项的删除体验很不好,也给用户带来了很大的麻烦. 实现效果图 具体实现代码 select.xml 主布局文件 ...

随机推荐

  1. 《MSSQL2008技术内幕:T-SQL语言基础》读书笔记(上)

    索引: 一.SQL Server的体系结构 二.查询 三.表表达式 四.集合运算 五.透视.逆透视及分组 六.数据修改 七.事务和并发 八.可编程对象 一.SQL Server体系结构 1.1 数据库 ...

  2. 高性能Javascript--高效的数据访问

    接上一篇,希望能写一个高性能Javascript专题. 第一篇:高性能Javascript--脚本的无阻塞加载策略. 参考摘录<高性能Javascript>. 经典计算机科学的一个问题是, ...

  3. ASP.NET MVC 视图(二)

    ASP.NET MVC 视图(二) 前言 上篇中对于视图引擎只是做了简单的演示,对于真正的理解视图引擎的工作过程可能还有点模糊,本篇将会对由MVC框架提供给我们的Razor视图引擎的整个执行过程做一个 ...

  4. iOS实现UICollectionViewDataSource与Controller的分离

    之前每次用到UICollectionView的时候都会都需要在Controller里面去实现DataSource & Delegate方法 单独Delegate方法还好不是很多, 但是再加上D ...

  5. 游戏编程系列[1]--游戏编程中RPC协议的使用

    RPC(Remote Procedure Call Protocol)--远程过程调用协议,它是一种通过网络从远程计算机程序上请求服务,而不需要了解底层网络技术的协议.RPC协议假定某些传输协议的存在 ...

  6. C#学习总结之集合

    一.集合接口和类型 命名空间:  集合类型  命名空间  一般集合 System.Collections   泛型集合 System.Collections.Generic   特定类型集合 Syst ...

  7. 如何处理CSS3属性前缀

    今天闲来无聊,重新来说说CSS3前缀的问题.在春节前和@一丝姐姐说起Sass中有关于gradient的mixins.姐姐说: 为什么还要用mixin呢?为什么不使用Autoprefixer?使用Aut ...

  8. for循环与for in,$('').each 与$.each的区别

    一:for循环与for in的区别 for...in 语句用于对数组或者对象的属性进行循环操作. 语法: for (变量 in 对象){    在此执行代码} for循环是对数组的元素进行循环,而不能 ...

  9. 挑子学习笔记:对数似然距离(Log-Likelihood Distance)

    转载请标明出处:http://www.cnblogs.com/tiaozistudy/p/log-likelihood_distance.html 本文是“挑子”在学习对数似然距离过程中的笔记摘录,文 ...

  10. 记2016腾讯 TST 校招面试经历,电面、笔试写代码、技术面、hr面,共5轮

    (出处:http://www.cnblogs.com/linguanh/) 前序: 距离  2016 腾讯 TST 校招面试结束已经5天了,3月27日至今,目前还在等待消息.从投简历到两轮电面,再到被 ...