/**
*
* 类描述:
*@author
* 2012-6-9
*/
public class MenuViewGroup extends GridView
{
public MenuViewGroup(Context context)
{
super(context);
}
public MenuViewGroup(Context context, AttributeSet attrs)
{
super(context, attrs);
}
public MenuViewGroup(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
}
@Override
public void dispatchDraw(Canvas canvas)
{
Paint paint=new Paint();
int count =getChildCount();
int[] childWidth=new int[count];
for(int i=0;i<count;i++)
{
if(i==0)
{
childWidth[i]=getChildAt(i).getWidth();
}
else
{
childWidth[i]= childWidth[i-1]+getChildAt(i).getWidth();
}
if(i < count - 1)
{
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.menu_line);
canvas.drawBitmap(bitmap, childWidth[i], 0, paint);
}
}
super.dispatchDraw(canvas);
}
}
Selector:
<item android:drawable="@drawable/black_bg_select" android:state_pressed="true"/>
<item android:drawable="@color/transparent_background"/>
xml
<com.jian.CaiViewGroup
android:id="@+id/menu_gridView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:fadingEdge="none"
android:stretchMode="columnWidth" />