2014-01-08 35 views
2

我希望我的GridLayout具有像下圖中的3 Buttons那樣的圓角。這是否需要與視圖的四捨五入等不同的代碼,例如Buttons,TextViews等?佈局上的圓角

gameplayGL.setBackgroundResource(R.drawable.roundedcorners); 
gameplayGL.setBackgroundColor(Color.BLUE); 
gameplayGL.getBackground().setAlpha(35); 

roundedcorners.xml

<shape 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 

    <corners 
     android:bottomLeftRadius="8dp" 
     android:bottomRightRadius="8dp" 
     android:topLeftRadius="8dp" 
     android:topRightRadius="8dp" /> 

</shape> 

enter image description here

+0

我試過我貼的代碼嗎?是的,它提供了我張貼的圖像的輸出。注意圍繞3個按鈕的佈局沒有圓角。 – Matt

回答

4

我敢肯定調用setBackgroundColor(Color.BLUE)覆蓋setBackgroundResource()調用。

嘗試進行不同的繪製資源,它是此

<shape 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="rectangle"> 

<corners 
    android:bottomLeftRadius="8dp" 
    android:bottomRightRadius="8dp" 
    android:topLeftRadius="8dp" 
    android:topRightRadius="8dp" /> 

<solid 
    android:color="#350000FF" /> 

</shape> 

然後設置GridView控件到的背景。你可能需要玩色彩值才能得到你想要的。

+0

杜!應該知道的!這工作完美,謝謝! – Matt