java - 布局上的圆角

标签 java android layout rounded-corners grid-layout

我希望我的 GridLayout 具有圆角,就像下图中的 3 个 Buttons 那样。这是否需要针对 View 的圆角(例如 ButtonsTextViews 等)使用不同的代码?

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>

enter image description here

最佳答案

我非常确定调用 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/

相关文章:

java - 在我使用 Google Play 服务版本 9.0.83 进行的路线跟踪 Activity 中, map 上没有显示标记

android - android捏缩放的比例限制

java - ExceptionMapper处理异常的过滤/映射顺序是什么?

java - 修改rt.jar可以吗?

java - 制作Android应用程序 "remember"数据,并在退出时保存

java - GridLayout 错误

css - jQuery Masonry/Isotope 和流体图像 : Momentary overlap on window resize

Android 应用程序在 Activity 更改时崩溃,可能受布局影响

java - 流过滤器线程安全

java - 匹配数字后跟下划线和数字的正则表达式?