我是新来的VectorDrawables.
我可以看到,默认vector drawables提供与Android工作室一样ic_menu_gallery,ic_menu_camera等都是伟大的工作.所以我尝试vector drawables通过将我转换png images为svg第一个并使用路径和填充值来制作矢量drawables 来创建我自己的东西,即替换svg文件中的android:pathDatafor d和android:fillColorfill标签.它以某种方式给了矢量drawables但扭曲或curlituted看.
如果我没有采取正确的方法,请建议我.
app:srcCompat与ImageView允许向后兼容使用载体可绘的.但是,你怎么能与其他使用它们View小号之外ImageView?例如,TextView属性就像android:drawableLeft.
同时使用矢量drawable作为android:iconwith MenuItem导致崩溃,但有以下异常:
Fatal Exception: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:626)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
at android.view.LayoutInflater.inflate(LayoutInflater.java:470)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at android.support.v7.view.menu.MenuItemImpl.setActionView(MenuItemImpl.java:621)
at android.support.v7.view.menu.MenuItemImpl.setActionView(MenuItemImpl.java:40)
at android.support.v4.view.MenuItemCompat.setActionView(MenuItemCompat.java:310)
at android.support.v7.view.SupportMenuInflater$MenuState.setItem(SupportMenuInflater.java:465)
at android.support.v7.view.SupportMenuInflater$MenuState.addItem(SupportMenuInflater.java:479)
at android.support.v7.view.SupportMenuInflater.parseMenu(SupportMenuInflater.java:196)
at android.support.v7.view.SupportMenuInflater.inflate(SupportMenuInflater.java:118)
at com.example.niceapp.context.main.MainActivity.onCreateOptionsMenu(MainActivity.java:101)
at android.app.Activity.onCreatePanelMenu(Activity.java:2578)
Run Code Online (Sandbox Code Playgroud)
使用支持库23.2.0,如何解决此问题?
我创建了AnimatedVectorDrawable,它运行得很好,现在我正在寻找一种方法来更改动画或在视图完成后隐藏视图.我希望有一个听众,但它看起来不像.有人可以帮忙吗?
编辑
所以我找到了一种解决方法,但不是一种非常优雅的方式.我做的是创建一个线程并轮询动画是否正在运行.
new Runnable() {
public void run() {
while(mLoop) {
if(mAnimatedVectorDrawable.isRunning()) {
Thread.sleep(mPollingInterval);
} else {
mLoop = false;
// TODO what ever
}
}
}
};
Run Code Online (Sandbox Code Playgroud)
如果有人找到更好的解决方案,请分享.
在谷歌IO,工具团队表现出短暂的可能性来定义具有特定后缀矢量绘图资源(如ic_heart_ 48像素,然后将转换到所有必要的密度PNG格式的.xml).不幸的是,除了IO录音之外,我找不到任何关于此功能的文档.
这是Build Tools还是Android Studio的功能?假设它是Build Tools的一部分,它是否已经可用?我应该使用哪个版本?我必须明确启用该功能吗?
Google是否以Android xml矢量格式提供其素材图标?
开发者网站发布了UI相关内容的培训指南,这是索引:
如果您对以下任何一项感兴趣,请访问以下链接:https: //developer.android.com/training/animation/
我找到了5种在Android中制作动画的方法:
动画的性能的View同属性动画平滑地改变rotation,alpha,scale等.
帧动画(AnimationDrawable):快速更改图片,使其看起来像动画
使用矢量(VectorDrawable)设计图像,并通过AnimatedVectorDrawable随时间编辑它们来制作动画.
使用Lottie,从After Effects中复制动画.LottieFiles提供了许多动画.
但是,Android也提供了一些内置工具,例如Scenes(允许您在共享的几个布局之间设置转换动画Views),Shared elements(这可以让您将一个View从一个布局传递Activity到另一个布局)等.
API 21中添加了许多(如果不是全部)这些功能,请单击此处 …
如何在我的Android应用程序中实现像许多音乐播放器一样的播放/暂停动画?我尝试了很多解决方案,但都没有效果.
这是我到目前为止所做的:MainActivity.java:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageButton = (ImageButton) findViewById(R.id.imageView);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Animatable animatable = (Animatable) imageButton.getDrawable();
animatable.start();
}
});
}
Run Code Online (Sandbox Code Playgroud)
activity_main.xml中:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="widefide.com.vectoranimation01.MainActivity">
<ImageButton
android:layout_width="wrap_content"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:id="@+id/imageView"
android:src="@drawable/play_pause"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
play_pause.xml:
<?xml version="1.0" encoding="utf-8"?>
<animated-selector xmlns:android="http://schemas.android.com/apk/res/android"
android:constantSize="true">
<item
android:drawable="@drawable/pause_ic"
android:state_checked="true"
android:id="@+id/pause_state" />
<item
android:drawable="@drawable/play_ic"
android:id="@+id/play_state" />
<transition android:fromId="@id/play_state" android:toId="@id/pause_state" android:reversible="true">
<animated-vector android:drawable="@drawable/play_ic">
<target …Run Code Online (Sandbox Code Playgroud) Android虽然支持SVG,但为什么要转换成VectorDrawable呢?
此代码示例显示了 Android 中的 SVG:
SVG svg = SVGParser.getSVGFromResource(getResources(), R.raw.android);
imageView.setImageDrawable(svg.createPictureDrawable());
Run Code Online (Sandbox Code Playgroud) 最近我想加入Vector Drawable我的工作.我正在使用滑行设置我的drawables.这是我的代码:
Glide
.with(mContext)
.load(resDrawable)
.placeholder(placeHolderResDrawable)
.centerCrop()
.bitmapTransform(new CropCircleTransformation(MyLruBitmapPool.getInstance()))
.into(imgRoundedView);
Run Code Online (Sandbox Code Playgroud)
在这里,我把vector drawable对resDrawable和placeHolderResDrawable.它在Lolipop设备上运行良好.但是当我测试它时它less than lolipop比它崩溃了.当试图把它放进drawable去的placeholder时候Resources$NotFoundException.
这是崩溃报告:
android.content.res.Resources $ NotFoundException:来自android.content.res.Resources的android.content.res.Resources.loadDrawable(Resources.java:3451)的可绘制资源ID#0x7f02013d的文件res/drawable/default_round_profile.xml. getDrawable(Resources.java:1894)位于com.bumptech.glide.request.GenericRequest.getPlaceholderDrawable(GenericRequest.java:395)的com.bumptech.glide.request.GenericRequest.begin(GenericRequest.java:265)com.bumptech .glide.manager.RequestTracker.runRequest(RequestTracker.java:36)at com.bumptech.glide.GenericRequestBuilder.into(GenericRequestBuilder.java:616)at com.bumptech.glide.GenericRequestBuilder.into(GenericRequestBuilder.java:652)at com.bumptech.glide.DrawableRequestBuilder.into(DrawableRequestBuilder.java:436)
VectorDrawableCompat 终于进入了SDK 23中的支持库.但它似乎没有用,或者我可能错过了一些东西.
drawable/mypic.xml:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="64dp"
android:width="64dp"
android:viewportHeight="600"
android:viewportWidth="600" >
<group
android:name="rotationGroup"
android:pivotX="300.0"
android:pivotY="300.0"
android:rotation="45.0" >
<path
android:name="v"
android:fillColor="#000000"
android:pathData="M300,70 l 0,-70 70,70 0,0 -70,70z" />
</group>
</vector>
Run Code Online (Sandbox Code Playgroud)
fragment_bla.xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/mypic"
android:scaleType="centerCrop" />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
此代码适用于Lollipop,但不适用于KitKat.我错过了什么?
例外:
09-06 14:26:53.637 31820-31820/com.bla E/AndroidRuntime? FATAL EXCEPTION: main
Process: com.bla, PID: 31560
android.view.InflateException: Binary XML file line #7: Error inflating class android.widget.ImageView
at android.view.LayoutInflater.createView(LayoutInflater.java:623)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:672)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at …Run Code Online (Sandbox Code Playgroud) 不久之前,矢量drawable已添加到支持库中,从那时起API中发生了很多变化:Gradle标志,初始化块,选择器,自定义XML属性等.问题是 - 如何正确使用它(在这些情况下支持lib v25):
XML和编程.
抱歉,如果这是重复的,但我努力搜索,但没有发现这个问题被问到......
回到过去的 Android 时代,您可以将类似这样的内容添加到 WebView 的源 html 中:
<img src='file:///android_res/drawable/my.png'/>
Run Code Online (Sandbox Code Playgroud)
并且它会在 WebView 中正确显示 my.png。但是 - Android 现在支持(并且更喜欢我们使用)这些新奇的矢量绘图,并且 Android Studio 的Vector Asset Studio使从 SVG 文件或其他文件导入它们变得非常容易。
最棒的是,为了向后兼容,在构建过程中会自动生成各种 dpi/屏幕尺寸的 .png 文件,以支持旧设备。因此,如果您的目标是较旧的设备,则那里有 .png 图像。
如果我能联系到他们就好了。因为,据我所知,使用矢量图形确实会破坏file:///android_res/drawable/ imgWebView 中的这些链接。这很奇怪,因为正如我所说,如果只是查看的话,可以查看 .png 文件。
我想过一些方法来解决这个问题,但没有一个有效:
由于 .png 是动态生成的并包含在 .apk 中,我想也许我可以直接指向生成的文件之一,例如file:///android_res/drawable-hdpi-v4/my.png. (我检查了 .apk 文件,其中之一就在那里......)但是没有这样的运气。破碎的图像。
好吧,我想——也许有一种方法可以让 WebView 直接显示矢量对象。也就是说,WebView 可能会识别一个<img src="file:///android_res/drawable/my_image.xml"/>或类似的东西。我的意思是,Chrome 可以渲染 svg 对吗?也许它也支持 .xml 矢量格式。但这里也没有骰子。(即使它有效,它也不太可能支持旧的 pre-chromium webview 版本。)
我尝试的第三件事是仅包含一个 xxxhdpi 大小的 .png,res/drawable以便 Web 视图能够找到它并希望显示它。不幸的是,这也不起作用。看来只要有一个 .xml 矢量/drawable …
android webview android-resources android-drawable android-vectordrawable