找了相关的资料终于写完了:
http://blog.csdn.net/jamin0107/article/details/6973845
和
http://emmet1988.iteye.com/blog/1097443
原来在scrollview中套listview需要将listview的高度固定
,这里就需要将listview的子类高度计算
同时还要注意子ListView的每个Item必须是LinearLayout
“引用连接中的话”------------------------------------------------------
只要在设置ListView的Adapter后调用此静态方法即可让ListView正确的显示在其父ListView的ListItem中。但是要注意的是,子ListView的每个Item必须是LinearLayout,不能是其他的,因为其他的Layout(如RelativeLayout)没有重写onMeasure(),所以会在onMeasure()时抛出异常。
在ScrollView中嵌套ListView(或者ScrollView)的另外一个问题就是,子ScrollView中无法滑动的(如果它没有显示完全的话),因为滑动事件会被父ScrollView吃掉,如果想要让子ScrollView也可以滑动,只能强行截取滑动事件,有牛人在论坛中发过代码说可以。虽然我没有亲自试过,但估计是可行的。
-------------------------------------------------------------
在listview.setAdapter()之后调用Utility.setListViewHeightBasedOnChilren(listview)就Okay 了。
public class Utility {
public static void setListViewHeightBasedOnChildren(ListView listView) {
//获取ListView对应的Adapter
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null) {
// pre-condition
return;
}
int totalHeight = 0;
for (int i = 0, len = listAdapter.getCount(); i < len; i++) { //listAdapter.getCount()返回数据项的数目
View listItem = listAdapter.getView(i, null, listView);
listItem.measure(0, 0); //计算子项View 的宽高
totalHeight += listItem.getMeasuredHeight(); //统计所有子项的总高度
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
//listView.getDividerHeight()获取子项间分隔符占用的高度
//params.height最后得到整个ListView完整显示需要的高度
listView.setLayoutParams(params);
}
}
Listview其他属性
1.去滑动到顶点和底边时的黑色阴影
[html] view plaincopy
android:fadingEdge="none"
2.去拖动时默认黑色底色
[html] view plaincopy
android:cacheColorHint=“#00000000”
3.去选中时的黄色底色
[html] view plaincopy
android:listSelector="#00000000"
<ListView
android:id="@+id/roundlistview01" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:background="@drawable/shape"
android:cacheColorHint="#00000000" android:drawSelectorOnTop="false"
android:fadingEdge="none" android:listSelector="#00000000"
android:layout_marginLeft="10dip" android:layout_marginRight="10dip">
</ListView>
圆角android:background="@drawable/shape":
shape.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 实心 透明色
<solid android:color="#FFFFFF"/>
-->
<gradient android:startColor="#F0F0F0"
android:endColor="#F0F0F0"
android:angle="90" />
<stroke
android:width="2dp"
android:color="#6C6C6C" />
<corners
android:radius="10dip" />
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp" />
</shape>
源代码:下载地址1:http://dl.iteye.com/topics/download/8bb55721-9bda-3271-ac3d-576a78e22624
分享到:
相关推荐
很多朋友因项目需求问题需要在ScrollView中嵌套使用ListView或ScrollView 但是彼此的滑动事件会发生冲突,网上大多数都是计算ListView的高度来解决这个问题,但个人亲手尝试 结果ListView的Item要是过多的话ListView...
android中scrollview与listview共存,内含源码导入Eclipse直接即可使用
Android仿小米商城商品详情界面UI,ScrollView嵌套ScrollView/WebView/ListView
安卓Android源码——下拉刷新控件(ListView好ScrollView版).rar
scrollview布局中的添加listview实现滚动效果,动态添加数据
这里是计算机专业-Andorid项目源码100套之一的Android下拉刷新控件(ListView好ScrollView版),类似于蘑菇街和迷尚 应用里的排列,希望能对大家有所帮助哦!
Android应用源码下拉刷新控件(ListView好ScrollView版).zip项目安卓应用源码下载Android应用源码下拉刷新控件(ListView好ScrollView版).zip项目安卓应用源码下载 1.适合学生毕业设计研究参考 2.适合个人学习研究...
android ScrollView,ListView 截屏并保存到图库
Android应用源码下拉刷新控件(ListView好ScrollView版).zip
安卓Android源码——下拉刷新控件(ListView好ScrollView版).zip
NULL 博文链接:https://justwyy.iteye.com/blog/1531106
NULL 博文链接:https://gundumw100.iteye.com/blog/1075286
Android应用源码开发Demo,主要用于毕业设计学习。
NULL 博文链接:https://gzsxt.iteye.com/blog/1971999
Android下拉刷新控件(ListView好ScrollView版)毕业设计—(包含完整源码可运行).zip
ListView侧滑删除的实现,SlideDeleteListView,针对ScrollView嵌套ListView试图和手势冲突优化
NULL 博文链接:https://1002878825-qq-com.iteye.com/blog/1843872
NULL 博文链接:https://hz-chenwenbiao-91.iteye.com/blog/2061735
NULL 博文链接:https://forlan.iteye.com/blog/2255857