2016-03-03 86 views
0

網絡佈局的列之間的垂直線我想提出一個原生的Android應用程序,我想畫兩列之間的垂直線在網格佈局,有沒有什麼辦法可以做到這一點? 在以下屏幕截圖中,您可以看到單元格之間和列之間的線條。基本上,我只是想用我自己的自定義風格來顯示網格。 This is the link to see the screenshots, apparently stack wont let me post a pic如何顯示在android系統

+0

檢查[這個答案](HTTP:// stackoverflow.com/a/23891978/2826147) –

+0

去下面的鏈接,你可能會發現你的解決方案http://stackoverflow.com/questions/12109126/android-gridview-row-dividers-separators –

+0

很多很好的解決方案。你認爲如果我們去了1px ppl而不是1dp,你覺得如何?該產品線在高規格設備上看起來不錯而且更薄。這是否工作? – hasan83

回答

1

添加verticalSpacing中可以添加保證金上述查看您的網格佈局並將GridView背景設置爲您想要的線條的顏色。

<GridView 
     android:id="@+id/grid_view" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="#DADADA" 
     android:verticalSpacing="1dp" 
     android:numColumns="2" /> 
1

您可以添加一條垂直線這樣的 -

<View 
android:layout_width="1dp" 
android:layout_height="match_parent" 
android:background="#000000" /> 

您可以設置高度按規定,如果需要

+0

我通常使用這種解決方案。但是,我不喜歡它有一個原因。該行是thik,看起來不太好。我們如何做到比1DP更細的線。 – hasan83

+0

即使您使用網格佈局,我也正在使用網格視圖佈局 –

+0

。你可以把它放在一個framelayout中,並且與這個建議的視圖一起。 – hasan83

0

如果您使用兩個LinearLayouts並排你可以使用框架分隔功能與易用性:

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:divider="?android:listDivider" 
    android:dividerPadding="2.5dp" 
    android:orientation="horizontal" 
    android:showDividers="middle" 
    android:weightSum="2" > ... </LinearLayout> 

參見:http://developer.android.com/reference/android/widget/LinearLayout.html