【问题标题】:Rounded corners on layout布局上的圆角
【发布时间】:2014-01-25 22:37:28
【问题描述】:

我希望我的GridLayout 具有像下图中的 3 Buttons 那样的圆角。这是否需要针对诸如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>

【问题讨论】:

  • 我是否尝试过我发布的代码?是的,它给出了我发布的图像的输出。请注意,围绕 3 个按钮的布局没有圆角。

标签: java android layout rounded-corners grid-layout


【解决方案1】:

我很确定调用 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的背景设置为那个。您可能必须使用颜色值才能得到您想要的。

【讨论】:

  • 杜!早该知道的!效果很好,谢谢!
猜你喜欢
  • 2019-05-01
  • 1970-01-01
  • 2016-12-26
  • 2013-04-16
  • 2016-01-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-04
相关资源
最近更新 更多