2014-01-08 57 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