由于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 >> , 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