安卓系统开关定制

问题描述

我正在尝试通过在 Switch 类

enter image description here

中进行更改来创建像 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); 。它就像,

enter image description here

当它被选中时,我还添加了动画,

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.zoominR.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>

这会在一个按钮中创建一个图像大小变化很小的动画,如下图所示,

enter image description here

还尝试在此 .xml 资源 here 中替换我的可绘制按钮,但没有成功。

不幸的是,它与预期的结果相去甚远。 iam试图在检查和未选中按钮时从一个可绘制的滑动到另一个滑动。任何帮助是极大的赞赏。感谢您阅读我的问题。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)