Android的添加自定义动画吐司吐司、自定义、动画、Android

2023-09-08 09:30:26 作者:卑微的喜欢

我需要创建一个自定义动画敬酒消息。现在我需要知道,如果这是可能的。我创建一个自定义视图敬酒,但我想不通我怎么可以添加自定义动画致祝酒辞。

下面是code我有这么远。

 私人无效showToast(){
        LayoutInflater充气= getLayoutInflater();

        查看布局= inflater.inflate(R.layout.custom_toast,
                (ViewGroup中)findViewById(R.id.custom_toast_layout_id));

        //设置消息
        TextView的文字=(TextView的)layout.findViewById(R.id.toast_text);
        text.setText(按钮是点击!);

        //吐司...
        吐司面包=新吐司(getApplicationContext());
        toast.setGravity(Gravity.CENTER_VERTICAL,0,0);
        toast.setDuration(Toast.LENGTH_LONG);
        toast.setView(布局);
        toast.show();
    }
});
}
 

解决方案

这是不可能与普通的Andr​​oid吐司类做到这一点。股票风格的祝酒词(的人加入到窗口管理器,而不是一个ViewGroup中)被限制在四个系统的动画,也不会接受你的项目的动画。如果您想使用不同的系统的动画与股票型机器人敬酒看看我是如何做到这一点在我的 SuperToasts库。它可能不值得为一个实例写这样的一类,所以我会建议,要么使用我的图书馆,如果你觉得它有用或写类似于举杯自定义视图类。你可以看到我是如何做到这一点的这个类的库。

怎样可以在日志自定义动画模块上添加文字呢 谢谢

I need to create a custom animated toast message. Now i need to know if that is possible. I've created a toast with a custom view but I cannot figure out how can I add custom animation to the toast.

Here is the code I have so far.

    private void showToast() {
        LayoutInflater inflater = getLayoutInflater();

        View layout = inflater.inflate(R.layout.custom_toast,
                (ViewGroup) findViewById(R.id.custom_toast_layout_id));

        // set a message
        TextView text = (TextView) layout.findViewById(R.id.toast_text);
        text.setText("Button is clicked!");

        // Toast...
        Toast toast = new Toast(getApplicationContext());
        toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
        toast.setDuration(Toast.LENGTH_LONG);
        toast.setView(layout);
        toast.show();       
    }
});
}

解决方案

It is not possible to do this with the stock Android Toast class. Stock style toasts (ones added to the WindowManager and not to a ViewGroup) are limited to four system animations and will not accept animations from your project. If you would like to use different system animations with stock type Android Toasts check out how I do it in my SuperToasts library. It may not be worth it to write such a class for one instance so I would recommend either using my library if you find it useful or writing a custom view class that resembles a toast. You can see how I do that in this class of the library.