GVKun编程网logo

RippleDrawable-以编程方式显示纹波效果

13

在本文中,您将会了解到关于RippleDrawable-以编程方式显示纹波效果的新资讯,并给出一些关于AndroidStudio错误:E/dalvikvm:找不到类’android.graphics.

在本文中,您将会了解到关于RippleDrawable-以编程方式显示纹波效果的新资讯,并给出一些关于Android Studio错误:E / dalvikvm:找不到类’android.graphics.drawable.RippleDrawable’、android – AnimationDrawable以编程方式没有动画列表xml、android – EditText中drawableLeft和drawableStart之间的区别是什么?、android – GradientDrawable以编程方式更改角度的实用技巧。

本文目录一览:

RippleDrawable-以编程方式显示纹波效果

RippleDrawable-以编程方式显示纹波效果

我有这样的看法

<Button    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="New Button"    android:id="@+id/button"    android:background="@drawable/ripple"    android:layout_centerVertical="true"    android:layout_alignParentStart="true" />

和涟漪.xml作为

<?xml version="1.0" encoding="utf-8"?><ripple    xmlns:android="http://schemas.android.com/apk/res/android"    android:color="?android:colorControlHighlight" >    <item android:id="@android:id/mask"        android:drawable="@android:color/white" /></ripple>

一切正常。当我触摸视图时,它会产生波纹效果。我正在寻找的是从代码中反复在视图上启动波纹动画。将其显示为不确定的进度。因此,海浪不断荡漾。

就像是

 Runnable runnable = new Runnable() {    @Override    public void run() {        RippleDrawable drawable = (RippleDrawable) button.getBackground();        drawable.showRipples(true, true); // <-- This is needed        handler.postDelayed(runnable, 500);    }};

这该怎么做?

答案1

小编典典

RippleDrawable响应压力和聚焦状态,前者提供您要查找的波纹动画。您可以使用来在主机视图上切换按下状态View.setPressed(boolean)

Runnable pressRunnable = new Runnable() {    @Override    public void run() {        button.setPressed(true);        button.postOnAnimationDelayed(unpressRunnable, 250);    }};Runnable unpressRunnable = new Runnable() {    @Override    public void run() {        button.setPressed(false);        button.postOnAnimationDelayed(pressRunnable, 250);    }};

请记住,用户触摸Button切换按钮也会切换按下状态,因此您可能想要删除或重新发布可运行项OnTouchListener

如果需要,您可以Drawable.setHotspot(float, float)在API
22+上使用或View.dispatchDrawableHotspotChanged(float, float)通过传递视图相对(x,y)坐标来控制波纹位置。

Android Studio错误:E / dalvikvm:找不到类’android.graphics.drawable.RippleDrawable’

Android Studio错误:E / dalvikvm:找不到类’android.graphics.drawable.RippleDrawable’

我正在研究一个项目,这个错误突然出现了:

E/dalvikvm: Could not find class ''android.graphics.drawable.rippledrawable'',referenced from method android.support.v7.widget.AppCompatimageHelper.hasOverlappingRendering

我将应用程序恢复到以前正在运行的版本,并且错误仍然存​​在.我创建了一个新项目,有一个空活动并在我的设备上运行它,错误仍然存​​在.我怎样才能解决这个问题?

解决方法

没有什么可以解决的.这只是提到您的代码(例如,库)具有对您的设备上不可用的类(android.graphics.drawable.rippledrawable)的引用.最有可能的是,您的设备运行的是Android 4.4或更早版本,因为此类是在Android 5.0中引入的.

这个特定的消息一直出现,因为我们的代码(例如,appcompat-v7)经常引用我们想要在较新的设备上使用但可以避免在旧设备上使用的类.

所以,请忽略它.

android – AnimationDrawable以编程方式没有动画列表xml

android – AnimationDrawable以编程方式没有动画列表xml

我处于某种情况,我想从动态图像列表中显示动画.我想使用AnimationDrawable为此目的,但不幸的是我被卡住了:(我的代码是
ImageView globe = (ImageView) findViewById(R.id.globe);

AnimationDrawable animation = new AnimationDrawable();
animation.setoneshot(true);

Resources res = this.getResources();

while (from <= to) {
    String name = "globe_" + String.format("%03d",from);
    int globeId = res.getIdentifier(name,"drawable",this.getPackageName());
    animation.addFrame(res.getDrawable(globeId),200);
    from++;
}

globe.setBackgroundDrawable(animation);
globe.post(new Runnable(){
        @Override
        public void run() {
            animation.start();
        }
});

解决方法

所以Animation.addFrame(Drawable frame,int duration)需要一个可以从Bitmap创建的drawable.

如果您的图像列表是动态加载的:

List<Bitmap> images;
int duration = 200;    

for(Bitmap image: images){
    BitmapDrawable frame = new BitmapDrawable(image);
    animation.addFrame(frame,duration);
}

试试这个,一定要工作.

android – EditText中drawableLeft和drawableStart之间的区别是什么?

android – EditText中drawableLeft和drawableStart之间的区别是什么?

起初我以为当我将系统语言改为阿拉伯语时,drawableStart会自动更改图标的位置,这是一种从右到左书写的语言.但是当我这样做时,什么也没发生.
所以我猜他们是一样的?

解决方法:

我不确定上面的答案是否正确.从我的实验中,除非您更改语言并启用RTL支持,否则图标始终位于同一位置.

drawableStart和drawableEnd仅在API级别17及更高级别的enable RTL support时开始切换侧面.

Change all of your app’s “left/right” layout properties to new
“start/end” equivalents.

  • If you are targeting your app to Android 4.2 (the app’s targetSdkVersion or minSdkVersion is 17 or higher), then you should
    use “start” and “end” instead of “left” and “right”. For example,
    android:paddingLeft should become android:paddingStart.

  • If you want your app to work with versions earlier than Android 4.2 (the app’s targetSdkVersion or minSdkVersion is 16 or less), then you
    should add “start” and end” in addition to “left” and “right”. For
    example, you’d use both android:paddingLeft and android:paddingStart.

android – GradientDrawable以编程方式更改角度

android – GradientDrawable以编程方式更改角度

我有跟随GradientDrawable的xml.如何以编程方式更改角度?
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient android:type="linear" 
       android:angle="45" 
       android:startColor="#FF0000" 
       android:endColor="#00FF00" />
</shape>

解决方法

GradientDrawable有一个名为:.setorientation(GradientDrawable.Orientation orientation)的方法,您可以使用此方法更改渐变的方向.您需要将XML扩展为GradientDrawable.

关于RippleDrawable-以编程方式显示纹波效果的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于Android Studio错误:E / dalvikvm:找不到类’android.graphics.drawable.RippleDrawable’、android – AnimationDrawable以编程方式没有动画列表xml、android – EditText中drawableLeft和drawableStart之间的区别是什么?、android – GradientDrawable以编程方式更改角度等相关内容,可以在本站寻找。

本文标签: