我正在为Android开发一个应用程序.在我的活动中,它包含一个线性布局.我想设置环型背景.所以我使用以下代码.
?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadiusRatio="2.7"
android:shape="ring"
android:thickness="16dp"
android:useLevel="false" >
<solid android:color="#EEEEEE" />
</shape>
Run Code Online (Sandbox Code Playgroud)
它工作正常.现在我想以编程方式更改上面代码中的厚度.我怎么能改变这个?我为此做了研发,但没有得到答案.
可能涉及以编程方式更改厚度。在 Android 代码中创建环形问题的答案提供了一些见解。
如果您只是想按比例放大或缩小环的厚度,正如您在评论中提到的那样,随着显示尺寸的增加/减少,那么您可能需要考虑使用XML 中的android:thicknessRatio或属性来执行此操作并删除属性。有关详细信息,请参阅文档。android:innerRadiusRatioandroid:thickness
我希望这有帮助。