<p>.要点一:去除ListView的scrollBar,添加ScrollView的scrollBar:</p>  
<ScrollView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight=""
android:scrollbars="vertical">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="5dp" android:paddingRight="5dp"
android:paddingTop="6dp" android:paddingBottom="6dp" android:background="@color/LightSteelBlue1"> <TextView android:id="@+id/text" android:text="列表如下:"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/White" android:layout_marginLeft="10dp" android:gravity="center_horizontal"
android:paddingTop="5dp" android:paddingBottom="5dp" android:clickable="true"/>
</LinearLayout>
<ListView android:id="@+id/list_alarm" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight=""
android:cacheColorHint="@color/LightCyan2" android:scrollbars="none"/>
</LinearLayout>
</ScrollView>

2.要点二:(设置ListView的高度,否则只能显示1-2行)

在setAdapter之后,在设置ListView的高度(不是wrap_content),其高度 = 每行高度 * 行数 + 行间距 * (行数 - 1),用ViewGroup.LayoutParams 设置ListView 的高度

private void setAdapter(){
ArrayAdapter<String> adapter = new ArrayAdapter<String> (MainActivity.this,android.R.layout.simple_list_item_1,listSource);
mListView.setAdapter(adapter);
setLvHeight();
} private void setLvHeight(){
ListAdapter adapter = mListView.getAdapter();
if(adapter == null){
ShowLog.d(TAG, "no data in ListView");
return;
}
int totalHeight = ;
for(int i = ;i < adapter.getCount(); i++){
View itemView = adapter.getView(i, null, mListView);
itemView.measure(, );
totalHeight += itemView.getMeasuredHeight();
}
ViewGroup.LayoutParams layoutParams = mListView.getLayoutParams();
layoutParams.height = totalHeight + (mListView.getDividerHeight() * (adapter.getCount() - ));//总行高+每行的间距
mListView_Alarm.setLayoutParams(layoutParams);
}

方法2:http://blog.csdn.net/kaixinbingju/article/details/8649276

ScrollView中添加ListView的更多相关文章

  1. 解决在ScrollView中套用ListView显示不正常

    最近在设计Android程序时,因为需要在ScrollView中添加一个ListView列表来显示一些信息.刚开始并没有想太多,但添加进去后才发现ListView不论怎样定义都只能显示一行,显示效果很 ...

  2. ScrollView中嵌套ListView的问题

    网上关于怎样在ScrollView中嵌套ListView的讨论有很多,我大概是搜索了一下,简单总结如下: 1.不要在ScrollView中嵌套ListView a.用一个LinearLayout来代替 ...

  3. [转载]Android: 如何实现ScrollView中含有ListView?

    原文地址:Android: 如何实现ScrollView中含有ListView?作者:mailofzxf ListView本身就含有ScrollView,因此把ListView放到ScrollView ...

  4. 实现ScrollView中包含ListView,动态设置ListView的高度

    ScrollView 中包含 ListView 的问题 : ScrollView和ListView会冲突,会导致ListView显示不全 <?xml version="1.0" ...

  5. ScrollView中嵌套ListView

    scrollview中嵌入listview,要是直接把listview嵌进scrollview中,listview的高度是固定的不能进行滑动.默认情况下Android是禁止在ScrollView中放入 ...

  6. Android 如何在ScrollView中嵌套ListView

    前几天因为项目的需要,要在一个ListView中放入另一个ListView,也即在一个ListView的每个ListItem中放入另外一个ListView.但刚开始的时候,会发现放入的小ListVie ...

  7. 解决ScrollView中包含ListView,导致ListView显示不全

    ScrollView 中包含 ListView 的问题 : ScrollView和ListView会冲突,会导致ListView显示不全 <?xml version="1.0" ...

  8. Android实战技巧:如何在ScrollView中嵌套ListView

    前几天因为项目的需要,要在一个ListView中放入另一个ListView,也即在一个ListView的每个ListItem中放入另外一个ListView.但刚开始的时候,会发现放入的小ListVie ...

  9. Android -- 在ScrollView中嵌套ListView

    在做一个工程,这个工程的布局可以相当的复杂,最外面是ScrollView,在ScrollView里面有两个Listview,这下好了,布局出来了,放在机子上跑,卡得想死有木有,信息乱跑乱出现,表示非常 ...

随机推荐

  1. BZOJ1635: [Usaco2007 Jan]Tallest Cow 最高的牛

    1635: [Usaco2007 Jan]Tallest Cow 最高的牛 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 346  Solved: 184 ...

  2. Delphi 把字符串读到流中的操作。

    var FReQuestM := TMemoryStream FReQuestM.Write(PChar(FcVoucherXML)^, Length(FcVoucherXML)); 这样就读到流中了 ...

  3. hdu3849-By Recognizing These Guys, We Find Social Networks Useful:双连通分量

    By Recognizing These Guys, We Find Social Networks Useful Time Limit: 2000/1000 MS (Java/Others)     ...

  4. HDU--3466(0-1背包+贪心/后效性)

    题意是: 给你一些钱 m ,然后在这个国家买东西, 共有 n 件物品,每件物品有  价格 P    价值 V    还有一个很特别的属性 Q, Q 指 你如过想买这件物品 你的手中至少有这钱Q . 虽 ...

  5. 自定义xcode文件模板

    下面两个路径都可以用于放模板文件 1. /Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File Template ...

  6. jsDelivr - Free open source CDN for javascript libraries, jQuery plugins, CSS frameworks, Fonts and more

    jsDelivr - Free open source CDN for javascript libraries, jQuery plugins, CSS frameworks, Fonts and ...

  7. hdu 2254 奥运

    点击打开hdu 2254 思路: 矩阵乘法 分析: 1 题目给定一个有向图,要求t1-t2天内v1-v2的路径的个数 2 根据离散数学里面的可达矩阵的性质,我们知道一个有向图的邻接矩阵的前n次幂的和即 ...

  8. 用Scrapy写一个爬虫

    昨天用python谢了一个简单爬虫,抓取页面图片: 但实际用到的爬虫需要处理很多复杂的环境,也需要更加的智能,重复发明轮子的事情不能干, 再说python向来以爬虫作为其擅长的一个领域,想必有许多成熟 ...

  9. lucene4.6 索引创建和搜索例子

    本文转自:http://blog.csdn.net/jyf211314/article/details/17503997           点击打开链接 lucene4.6小例子,Lucene全文检 ...

  10. poj 3134 Power Calculus(迭代加深dfs+强剪枝)

    Description Starting with x and repeatedly multiplying by x, we can compute x31 with thirty multipli ...