之前有個項目有類似這樣的界面
于是呢,就~
I have a ExpandableListView
I have a GridView
en~a!
ExpandableGridView
忘記把鼠標錄進來,點擊事件和傻逼一樣低飒。。。
下面是分割線
<dependency>
<groupId>com.linyuzai</groupId>
<artifactId>expandablegridview</artifactId>
<version>1.2.0</version>
<type>pom</type>
</dependency>
------------------------------------------------
compile 'com.linyuzai:expandablegridview:1.2.0'
下面又是分割線
上面蕾各,對,我真的很無聊
然后是布局
<com.linyuzai.expandablegridview.ExpandableGridView
xmlns:grid="http://schemas.android.com/apk/res-auto"
android:id="@+id/egv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
grid:group_clickable="true"
grid:horizontal_spacing="10dp"
grid:overwrite_measure="true"
grid:vertical_spacing="10dp" />
horizontal_spacing和vertical_spacing是GridView的屬性庆揪,然后overwrite_measure式曲,比如在外面套了一個ScrollView就不用自己重寫了。如果group_clickable設為了false,發(fā)現ChildView不顯示吝羞,點擊也沒用兰伤,調用一下ExpandableGridView.expandAll();接下來是Adapter~
public ExpandableGridAdapter getExpandableGridAdapter();
public void setExpandableGridAdapter(ExpandableGridAdapter adapter);
class MyAdapter1 extends ExpandableGridAdapter {
@Override
public int getGridGroupCount() {
return 0;
}
@Override
public int getGridChildCount(int gridGroupPosition) {
return 0;
}
@Override
public View getGridGroupView(int gridGroupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
return null;
}
@Override
public View getGridChildView(int gridGroupPosition, int gridChildPosition, View convertView, ViewGroup parent) {
return null;
}
@Override
public int getNumColumns(int gridGroupPosition) {
return 0;
}
}
class MyAdapter2 extends SimpleExpandableGridAdapter<String> {
public MyAdapter(List<List<String>> dataList) {
super(dataList);
}
@Override
public View getGridGroupView(int gridGroupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
return convertView;
}
@Override
public View getGridChildView(int gridGroupPosition, int gridChildPosition, View convertView, ViewGroup parent) {
return convertView;
}
@Override
public int getNumColumns(int gridGroupPosition) {
return 0;
}
}
最后還有一個
public void setOnGridItemClickListener(OnGridItemClickListener listener);
哦,ViewHolder還是得自己寫钧排。然后應該沒有漏下什么了敦腔,恩(思考臉)