ScollView和ListView 发生冲突解决方案

由于ScollView 和listView 共同使用 就会造成listview 无法滑动 正所谓 一山不能容二虎 要想使他们双剑合一 天下无敌 必须 要自定义一个listveiw 才能够共同的滑板鞋 共同摩擦。。。

package com.example.winter.scollview_listview;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ListView;

/**
 * Created by WINTER on 2015/9/13.
 */
public class listviewcustom extends ListView {
    public listviewcustom(Context context) {
        super(context);
    }

    public listviewcustom(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);
    }
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">


    <ScrollView

        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout

            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">


            <com.example.winter.scollview_listview.listviewcustom
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:entries="@array/array">

            </com.example.winter.scollview_listview.listviewcustom>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="呆猫" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="呆猫" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="呆猫" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="呆猫" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="呆猫" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="呆猫" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="呆猫" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="呆猫" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="呆猫" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="呆猫" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="呆猫" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="呆猫" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="呆猫" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="呆猫" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="呆猫" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="呆猫" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="呆猫" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="呆猫" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="呆猫" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="呆猫" />

            v

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="呆猫" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="呆猫" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="呆猫" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="呆猫" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="呆猫" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="呆猫" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="呆猫" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="呆猫" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="呆猫" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="呆猫" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="呆猫" />


            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="呆猫" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="呆猫" />

        </LinearLayout>
    </ScrollView>
</LinearLayout>

//写在资源文件String 里


<resources>
    <string name="app_name">ScollView_listview</string>

    <string name="hello_world">Hello world!</string>
    <string name="action_settings">Settings</string>
    <string-array name="array">

        <item>笨笨的码君</item>
        <item>笨笨的码君</item>
        <item>笨笨的码君</item>
        <item>笨笨的码君</item>
        <item>笨笨的码君</item>
        <item>笨笨的码君</item>
        <item>笨笨的码君</item>
        <item>笨笨的码君</item>
        <item>笨笨的码君</item>
        <item>笨笨的码君</item>
        <item>笨笨的码君</item>
        <item>笨笨的码君</item>
        <item>笨笨的码君</item>
        <item>笨笨的码君</item>
        <item>笨笨的码君</item>
        <item>笨笨的码君</item>


    </string-array>
</resources>

未自定义listiew 前 效果这里写图片描述

自定义listiew 后 效果这里写图片描述

demo 下载地址

http://download.csdn.net/detail/bxllove/9103339

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值