最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android中控件GridView實(shí)現(xiàn)設(shè)置行列分割線的方法示例

 更新時(shí)間:2017年01月24日 11:43:56   作者:dwtedx  
這篇文章主要介紹了利用Android中控件GridView實(shí)現(xiàn)設(shè)置行列分割線的方法,文中給出了詳細(xì)的介紹與示例代碼,相信對大家具有一定的參考價(jià)值,有需要的朋友們下面來一起看看吧。

前言

雖然Aandroid目前已經(jīng)有RecyclerView了、非常強(qiáng)大的一個(gè)View、可以直接控制成ListView以及GridView等、而且畫框線也比較方便、但是呢在很多情況下我們不得不仍然使用GridView來實(shí)現(xiàn)布局、那么在這個(gè)時(shí)候我們又要怎么來對GridViw進(jìn)行畫框線呢、下面將提供兩種實(shí)現(xiàn)方式、大家可以選擇一下

一、設(shè)置垂直、橫向間距、通過GRIDVIEW和ITEM的背景色來實(shí)現(xiàn)

     1、設(shè)置GridView背景色

     2、設(shè)置水平和豎直方向間隔:android:horizontalSpacingandroid:verticalSpacing

      3、設(shè)置GridView的item的背景色及其選中后的顏色

XML代碼如下

<GridView 
 android:id="@ id/gridView2" 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 android:layout_below="@ id/textView1" 
 android:layout_marginTop="30dp" 
 android:background="#999999" 
 android:horizontalSpacing="0.5dp" 
 android:verticalSpacing="0.5dp" 
 android:padding="2dp" 
 android:numColumns="3" > 

item布局

<?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:orientation="vertical" 
 android:gravity="center" 
 android:background="@android:color/whith"> 
 
 <TextView 
  android:id="@ id/textView1" 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content" 
  android:textSize="20sp" 
  android:padding="10dp" 
  android:text="TextView" /> 
 
</LinearLayout> 

二、設(shè)置選擇器

這種方式就是設(shè)置item的選擇器的android:background屬性來實(shí)現(xiàn)的

gv_selector代碼

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
 <item 
  android:state_selected="true" > 
  <shape android:shape="rectangle"> 
    <solid 
    android:color="#CCCCCC" 
    /> 
    <stroke android:width="1.0px" android:color="#999999" /> 
  </shape> 
 </item> 
 <item 
  android:state_pressed="true" > 
  <shape android:shape="rectangle"> 
    <solid 
    android:color="#CCCCCC" 
    /> 
    <stroke android:width="1.0px" android:color="#999999" /> 
  </shape> 
 </item> 
 <item> 
  <shape android:shape="rectangle"> 
   <stroke android:width="1.0px" android:color="#999999" /> 
  </shape> 
 </item> 
</selector> 

至此兩種方法已經(jīng)寫完了、有細(xì)心的朋友可能會(huì)發(fā)現(xiàn)第二種方法的中間的網(wǎng)格線比邊線要粗兩倍、這也是第二種方法的一個(gè)不足的地方

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,如果有疑問大家可以留言交流。

相關(guān)文章

最新評論

裕民县| 漳浦县| 金昌市| 淮滨县| 法库县| 乌鲁木齐市| 石嘴山市| 宁河县| 南乐县| 兴隆县| 揭西县| 榆树市| 青岛市| 乡宁县| 南充市| 历史| 平果县| 伊宁市| 通州区| 蕲春县| 南乐县| 天峨县| 华容县| 北碚区| 大竹县| 高要市| 黄梅县| 阿拉善右旗| 安陆市| 西丰县| 澎湖县| 彩票| 饶平县| 五河县| 调兵山市| 宁安市| 麦盖提县| 永寿县| 三明市| 金堂县| 祁门县|