我希望我的 GridLayout
具有圆角,就像下图中的 3 个 Buttons
那样。这是否需要针对 View 的圆角(例如 Buttons
、TextViews
等)使用不同的代码?
gameplayGL.setBackgroundResource(R.drawable.roundedcorners);
gameplayGL.setBackgroundColor(Color.BLUE);
gameplayGL.getBackground().setAlpha(35);
圆角.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>
最佳答案
我非常确定调用 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 的背景设置为该背景。您可能需要调整颜色值才能得到您想要的效果。
关于java - 布局上的圆角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20985302/