由于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 下载地址