gpt4 book ai didi

Android Drawable (Progress Bar, Switch) 渲染问题

转载 作者:太空宇宙 更新时间:2023-11-03 12:07:01 24 4
gpt4 key购买 nike

我正在尝试实现以下 UI。我正在使用带有 ADT 插件的 Eclipse。

Spotify UI

下面是圆【白+深灰】的实现(circle_shape.xml):

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape android:shape="ring" android:innerRadius="65dp" android:thickness="10dp"
android:useLevel="false">
<solid android:color="@android:color/white" />
</shape>
</item>
<item android:id="@android:id/progress">
<shape android:shape="ring" android:innerRadius="57dp" android:thickness="8dp" android:useLevel="false">
<solid android:color="#FF393939" />
</shape>
</item>
</layer-list>

和进度条[绿色] (circle_progress_bar.xml)as:

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="270" android:toDegrees="270">
<shape android:innerRadius="65dp" android:shape="ring" android:thickness="10dp">
<gradient android:angle="0" android:endColor="#FF00FF00" android:startColor="#FF00FF00" android:type="sweep" android:useLevel="false" />
</shape>
</rotate>

在布局 xml 文件中为:

<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_alignBottom="@+id/repeat"
android:layout_centerHorizontal="true"
android:layout_marginBottom="36dp"
android:background="@drawable/circle_shape"
android:indeterminate="false"
android:max="100"
android:progress="65"
android:progressDrawable="@drawable/circular_progress_bar" />

问题 1: 上面的代码给出了我想要的精确形状,但仅限于 API 19 和 API 20。当我将 Eclipse 中的预览模式切换到 API 21 时,progressDrawable 似乎填满了整个圆圈,只剩下一个圆圈填满与绿色。我不知道如何在 Android L 上做同样的事情。

问题 2: 这与开关按钮有关。在 API 21 中,我可以轻松设置

<android:textOn="" android:textOff="">

而且按钮看起来不错。但是,如果我在 API19 中查看相同内容,Thumb 可绘制对象会变形(挤压),直到我使用 textOn 和 textOff 属性设置一些文本。

有人可以帮我做同样的事情吗?

如果问题看起来不够有建设性,请随时移动/关闭问题。但请将我重定向到其他一些有用的资源。

编辑 1:以下是问题 2 的屏幕截图 API 19 and API 21 Comparison

switch 的 XML 如下:

<Switch
android:id="@+id/switch1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/repeat"
android:layout_alignBottom="@+id/repeat"
android:layout_alignParentLeft="true"
android:background="@drawable/toogle_selector"
android:checked="true"
android:thumb="@drawable/circle_1"
android:track="@drawable/transparent"
android:textOn=""
android:textOff=""/>

最佳答案

找到解决问题的方法

在“Circular_progress_bar”中

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="270"
android:toDegrees="270" >

<shape
android:innerRadius="65dp"
android:shape="ring"
android:thickness="10dp"
android:useLevel="true" >
<gradient
android:angle="0"
android:endColor="#FF00FF00"
android:startColor="#FF00FF00"
android:type="sweep"
android:useLevel="false" />
</shape>

</rotate>

因为android:useLevel="true" 默认为 false 为 API 级别 21

之前 enter image description here

之后 enter image description here

关于Android Drawable (Progress Bar, Switch) 渲染问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27144683/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com