Android開發ScrollView嵌套ListView的處理方法

 想要使用ScrollView來實現界面滾動,但是由於列表複雜,又要使用ListView加載數據,那麼就要實現嵌套。

只需要繼承ListView並重寫以下方法:

// 該自定義控件只是重寫了ListView的onMeasure方法,使其不會出現滾動條。
    @Override
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);
    }


 然後使用如下嵌套方式即可:

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

        <LinearLayout     
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
			
		<com.demo.list.view.MyListView
			android:layout_width="match_parent"
			android:layout_height="match_parent"/>

        </LinearLayout>

</ScrollView>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章