本人第一次写博客,有不正确的地方请大神们多多指教,要写博客了,想想都有点小激动,这些内容都是自己在项目中摸索出来的。
今天主要讲的内容是ScrollView和ListView滑动冲突的问题,我猜大家在布局中应该经常使用这两个控件,单独用非常好,结合起来一起使用问题就来了。比如说:滑动不灵
敏,Listview显示不全等等。
下面我就教大家如何解决这些问题,相信网上也有很多办法,大神们总结出来4-5种解决滑动冲突的办法,在这里我给大家提供一个简单快捷的办法。
首先自定义一个ListView,代码如下:
package com.cssiot.reminders.widget;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ListView;
/**
* Created by star on 2015/11/23.
*/
public class ScrollViewListView extends ListView {
public ScrollViewListView(Context context) {
super(context);
}
public ScrollViewListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ScrollViewListView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
}
然后在布局文件中引用这个控件,部分代码如下:
<com.cssiot.reminders.widget.ScrollViewListView
android:id="@+id/clause_lv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@null"
android:layout_above="@+id/add_clause_btn"
android:layout_below="@+id/scroll"
android:background="@color/project_hide_bg"
android:listSelector="@null"
android:cacheColorHint="@null"/>
接下来改怎么实现功能都和正常的Listview一样的使用。这个办法是亲自实践过的,绝对可靠可行。好了,今天就到这吧。谢谢!