如何解决安卓系统开关定制
我正在尝试通过在 Switch 类 中进行更改来创建像 https://github.com/LineageOS/android_frameworks_base/blob/lineage-17.1/core/java/android/widget/Switch.java 这样的自定义 Switch 设计。
在线 Switch.java#L1289 drawable.setBounds(L,T,R,B) 被 draw() 方法用来告诉 Drawable 它在哪里绘制以及它应该有多大.对于我的用例,我为它声明了两个 drawable 和 setBounds。像, mThumbDrawable.setBounds(71,166,95); 和 mThumbDrawableNew.setBounds(0,95,95); 。它就像,
当它被选中时,我还添加了动画,
ImageView mThumbDrawable1= new ImageView(context);
ImageView mThumbDrawable2= new ImageView(context);
mThumbDrawable1.setimageDrawable(mThumbDrawable);
mThumbDrawable2.setimageDrawable(mThumbDrawableTest);
Animation zoomin = AnimationUtils.loadAnimation(getContext(),android.R.anim.zoomin);
Animation zoomout = AnimationUtils.loadAnimation(getContext(),android.R.anim.zoomout);
mThumbDrawable1.setAnimation(zoomin);
mThumbDrawable2.setAnimation(zoomout);
mThumbDrawable1.startAnimation(zoomin);
mThumbDrawable2.startAnimation(zoomout);
path 中的 R.anim.zoomin 和 R.anim.zoomout
zoomin.xml
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="0"
android:toXScale="1.2"
android:fromYScale="0"
android:toYScale="1.2"
android:pivotX="50%"
android:pivotY="50%"
android:duration="2000"
android:fillAfter="true">
</scale>
zoomout.xml*
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="2.0"
android:toXScale="0"
android:fromYScale="2.0"
android:toYScale="0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="2000"
android:fillAfter="true">
</scale>
这会在一个按钮中创建一个图像大小变化很小的动画,如下图所示,
还尝试在此 .xml 资源 here 中替换我的可绘制按钮,但没有成功。
不幸的是,它与预期的结果相去甚远。 iam试图在检查和未选中按钮时从一个可绘制的滑动到另一个滑动。任何帮助是极大的赞赏。感谢您阅读我的问题。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。