1. Layout files
<LinearLayout
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<extra.view.MyGridView
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:horizontalSpacing="2dp"
android:listSelector="#ffffff"
android:numColumns="2"
android:padding="2dp"
android:scrollbars="none"
android:verticalSpacing="2dp" />
</LinearLayout>
2. Customizing the ListView
package com.example.chechengwang.view;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ListView;
/**
* 余天然 on 2015/7/27 10:19
* 邮箱:[email protected]
* 博客:http://my.oschina.net/u/2345676/blog
* 座右铭:知识来自积累,经验源于总结
*/
public class MyListView extends ListView {
public MyListView(Context context) {
super(context);
}
public MyListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
/span>public mylistview ( context Context attributeset Attrs int defstyleattr ) {
super(context, attrs, defStyleAttr);
}
@Override
/span>public void Onmeasure ( int Widthmeasurespec int ) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
}
From for notes (Wiz)
Case: Nested listview in ScrollView, avoid: 1. ListView displays only the first item, 2.ScrollView automatically scrolls to the first position of the ListView