android scrollview listview显示不全
原来处理方法是重写ListView
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ListView; public class MyListView extends ListView { public MyListView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public MyListView(Context context, AttributeSet attrs) {
super(context, attrs);
} public MyListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
} @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
} @Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if(ev.getAction() == MotionEvent.ACTION_MOVE){
return true;
}
return super.dispatchTouchEvent(ev);
}
}
试了这种方法还是显示不全 总是少二项内容
又使用了
public static void setListViewHeightBasedOnChildren(ListView listView) {
// 获取ListView对应的Adapter
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null) {
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);
}
还是一样效果 少二项内容
最后在网上找到有人重写LinearLayout显示列表
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.LinearLayout; /***
*
* @author FreePC
*
*/
public class LinearLayoutForListView extends LinearLayout
{
private BaseAdapter adapter;
private OnItemClickListener onItemClickListener; /**
* 通过 Java代码 实例化
* @param context
*/
public LinearLayoutForListView(Context context)
{
super(context);
//设置LinearLayoutForListView为垂直布局,否者默认为水平布局,容易疏忽导致子项显示不全
LinearLayoutForListView.this.setOrientation(LinearLayout.VERTICAL);
} /**
* 此构造函数可以允许我们通过 XML的方式注册 控件
* @param context
* @param attrs
*/
public LinearLayoutForListView(Context context, AttributeSet attrs)
{
super(context, attrs);
LinearLayoutForListView.this.setOrientation(LinearLayout.VERTICAL);
} /**
* 设置适配器
*
* @param adpater
*/
public void setAdapter(BaseAdapter adpater)
{
this.adapter = adpater;
bindLinearLayout();
} /**
* 获取适配器Adapter
*
* @return adapter
*/
public BaseAdapter getAdpater()
{
return adapter;
} /**
* 绑定布局:将每个子项的视图view添加进此线性布局LinearLayout中
*/
public void bindLinearLayout()
{
int count = adapter.getCount();
for (int i = 0; i < count; i++)
{
View v = adapter.getView(i, null, null); if (i != count - 1)
{ //添加每项item之间的分割线
v = addLine(v);
}
addView(v, i);
}
setItemClickListener();
Log.v("countTAG", "" + count);
} /**
* 添加每项item之间的分割线
*
* @param view
* @return
*/
public View addLine(View view)
{
//分割线view
View lineView = new View(view.getContext()); // 将数据从dip(即dp)转换到px,第一参数为数据原单位(此为DIP),第二参数为要转换的数据值
float fPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
(float) 0.5, view.getResources().getDisplayMetrics());
int iPx = Math.round(fPx); LayoutParams layoutParams = new LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, iPx);
lineView.setLayoutParams(layoutParams);
lineView.setBackgroundColor(view.getSolidColor()); LinearLayout ly = new LinearLayout(view.getContext());
ly.setOrientation(LinearLayout.VERTICAL); ly.addView(view);
ly.addView(lineView); return ly;
} /**
* 设置点击子项事件监听对象
* @param onItemClickListener
*/
public void setOnItemClickListener(OnItemClickListener onItemClickListener)
{
this.onItemClickListener = onItemClickListener;
setItemClickListener();
} /**
* 获取点击子项事件监听对象
* @return
*/
public OnItemClickListener getOnItemClickListener()
{
return onItemClickListen
这种方法完全可以搞定,在原来开发当中 上面二个方法都可以搞定不知道这次为什么不行
我怀疑是布局问题
<ScrollView
android:id="@id/myscrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/v_common_line_color"
android:orientation="vertical"
android:scrollbars="none" > <RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8.0dip"
android:orientation="vertical" > <FrameLayout
android:id="@id/frame_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" > <ImageView
android:layout_width="match_parent"
android:layout_height="200.0dip"
android:background="@drawable/home_cover2"
android:scaleType="centerCrop" /> <RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|left"
android:layout_marginBottom="8.0dip"
android:layout_marginLeft="16.0dip" > <TextView
android:id="@id/txt_city"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textSize="@dimen/font18" /> <TextView
android:id="@id/txt_weather"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/txt_city"
android:layout_gravity="bottom|left"
android:textColor="@color/white"
android:textSize="@dimen/font18" />
</RelativeLayout>
</FrameLayout> <LinearLayout
android:id="@id/linear_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/frame_layout"
android:layout_marginTop="8.0dp"
android:background="@drawable/layout_background_corners"
android:orientation="vertical"
android:padding="8.0dip" > <TextView
android:id="@id/txtTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textColor="@color/black2"
android:textSize="@dimen/font16" />
</LinearLayout> <ListView
android:id="@id/liv_trip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/linear_title"
android:layout_marginBottom="8.0dip"
android:layout_marginTop="8.0dip"
android:divider="@color/cccccc"
android:dividerHeight="0px"
android:fadingEdge="none" />
</RelativeLayout>
</ScrollView>
item布局是
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/v_common_line_color"> </LinearLayout>
android scrollview listview显示不全的更多相关文章
- Android 关于listView 显示不全的问题
刚刚在项目中发现一个bug,我是用ScrollView 嵌套 ListView的,但是我的数据只能显示一条,开始我还以为是数据有错误,经过排查以后发现是正确的 百度发现 android的架构好像没有考 ...
- 解决ScrollView中包含ListView,导致ListView显示不全
ScrollView 中包含 ListView 的问题 : ScrollView和ListView会冲突,会导致ListView显示不全 <?xml version="1.0" ...
- android listView多层嵌套listView显示不全问题
最近在做项目,需要用到listVIew多层嵌套listVIew的需求,先发现已下两个处理办法比较好用 第一种: public class ListViewNesting extends ListVie ...
- ScrollView镶嵌listview显示不全的原因
当ScrollView镶嵌listview会显示不全,通过查看ScrollView测量高度的源码,会发现ScrollView重写了父类viewGroup的measureChildWithMargins ...
- Android在ListView显示图片(重复混乱闪烁问题)
Android在ListView显示图片(重复混乱闪烁问题) 1.原因分析 ListView item缓存机制: 为了使得性能更优,ListView会缓存行item(某行相应的View). ListV ...
- Android 问题解决 HorizontalScrollView显示不全(转)
原链接:https://www.jianshu.com/p/003adbcaff9d Android 问题解决 HorizontalScrollView显示不全 <HorizontalScrol ...
- Android 6.0+ RecyclerView嵌套在ScrollView中显示不全
ScrollView嵌套RecyclerView在Android6.0以下能正常显示,但是在6.0以上就会出现RecyclerView显示不全的bug.尝试多种方法之后终于找到解决办法,特在此记录下. ...
- android -------- 解决RecyclerView显示不全只显示一条item的问题
布局文件1 <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android= ...
- Android 自定义 ListView 显示网络上 JSON 格式歌曲列表
本文内容 环境 项目结构 演示自定义 ListView 显示网络上 JSON 歌曲列表 参考资料 本文最开始看的是一个国人翻译的文章,没有源代码可下载,根据文中提供的代码片段,自己新建的项目(比较可恶 ...
随机推荐
- 【HAOI2014】走出金字塔
神奇…… 原题: 在探险的过程中,考古学家Dr. Kong 无意地被困在一个金字塔中.金字塔中的每个房间都是三角形.Dr. Kong可以破壁走到相邻的房间去. 例如,如果他目前处于三角形(2,2)房间 ...
- 【shell编程】之基础知识-常用命令
一.Shell echo命令 Shell 的 echo 指令与 PHP 的 echo 指令类似,都是用于字符串的输出.命令格式: echo string 您可以使用echo实现更复杂的输出格式控制. ...
- 推荐一些好的linux学习网站
菜鸟教程:这个网站有jsp,php,c,android等等入门教程,很适合入门的新手和想多学一门语言的人 传送门http://www.runoob.com/ linux命令那么多,怎么记,给一个lin ...
- Centos7部署ntp服务器同步时间以及直接将本地时间同步为北京时间
一.查看配置 查看时区列表: timedatectl list-timezones|grep Asia 查看当前时间: date 查看当前设置: [root@localhost ~]# timedat ...
- MySQL Disk--SSD和HDD的性能
========================================================= 机械硬盘的性能 7200转/分的STAT硬盘平均物理寻道时间是9ms 10000转/ ...
- day44 数据库学习 索引 引用自egon 老师博客
MySQL索引管理 总结 #索引是存在硬盘中的, #索引的功能, 1.可以加速查询 2.但是他会降低写入和删除的速度 所以不能乱加索引 总结二 1 最左前缀匹配原则 2设置的索引,它的字段中的内容占空 ...
- 自动化部署--shell脚本--1
传统部署方式1.纯手工scp2.纯手工登录git pull .svn update3.纯手工xftp往上拉4.开发给打一个压缩包,rz上去.解压 传统部署缺点:1.全程运维参与,占用大量时间2.上线速 ...
- 深入理解 content 计数器
计数器可以说是content的重点, 因为此功能非常强大, 实用, 并且不具有可替代性, 甚至可以实现连JavaScript都不好实现的效果. 所谓css计数器效果, 就是使用CSS代码实现随元素的数 ...
- CentOS6.5系统下RPM包安装MySQL5.6(转)
1.查看操作系统相关信息. [root@linuxidc ~]# cat /etc/issue CentOS release 6.5 (Final) Kernel \r on an \m [root@ ...
- 使用JMeter进行RESTful API测试
使用JMeter进行RESTful API测试 在哪里设置实现最优脚本重用的属性 由于支持云的应用程序通常可以轻松.快速地进行复制和部署,所以可以在多种环境中对其进行测试.如果您需要在多个环境中测试和 ...