参考:http://blog.csdn.net/jdsjlzx/article/details/44182693
直接上代码不多说:
GridView界面视图:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:orientation="vertical" >
<GridView
android:id="@+id/ble_gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="2"
android:stretchMode="columnWidth"
android:smoothScrollbar="true"
android:listSelector="@null"
android:verticalSpacing="0px"
android:horizontalSpacing="0px"
android:soundEffectsEnabled="true"
>
</GridView>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/gridview_divider"
android:orientation="vertical"
>
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="115dp"
android:layout_gravity="center"
android:scaleType="center" />
<bluetoothsoc.serialport.view.ScrollingTextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:gravity="center"
android:singleLine="true"
android:marqueeRepeatLimit="marquee_forever"
android:focusableInTouchMode="true"
android:textColor="@android:color/white"
android:textSize="32dp" />
</LinearLayout>
</RelativeLayout>
gridview_divider.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"><shape android:shape="rectangle">
<stroke android:width="1.0px" android:color="@android:color/white" />
<gradient android:angle="270.0" android:endColor="#ffe8ecef" android:startColor="#ffe8ecef" />
</shape></item>
<item android:state_focused="true"><shape android:shape="rectangle">
<gradient android:angle="270.0" android:endColor="#ffe8ecef" android:startColor="#ffe8ecef" />
<stroke android:width="1.0px" android:color="@android:color/white" />
</shape></item>
<item><shape android:shape="rectangle">
<gradient android:angle="270.0" android:endColor="#000000" android:startColor="#000000" />
<stroke android:width="1.0px" android:color="@android:color/white" />
</shape></item>
</selector>