VectorDrawable-Android의 롤리팝 이전 버전에서 어떻게 든 사용할 수 있습니까? [닫은]
배경
Android는 이제 " VectorDrawable "(및 AnimatedVectorDrawable , BTW) 이라는 클래스를 통해 일종의 벡터 드로잉을 지원합니다 . Android-Studio 의 새로운 기능을 살펴보면서 이에 대해 알아 냈습니다 .
이 여러 폴더 (에 여러 개의 파일을 넣어하지 말 것 궁금 mdpi
, hdpi
, xhdpi
, 등). 그것은 좋을 것이고 경우에 따라 앱 크기를 최소화 할 수 있습니다.
질문
이 새로운 수업에 대해 몇 가지 질문을하고 싶습니다.
Google의 지원 라이브러리 라이브러리를 통해 이전 Android 버전에서 사용할 수 있습니까?
작동 방식에 익숙하지 않지만 Lollipop에서 SVG 파일을 처리 할 수 있습니까? SVG 파일에서 달성 할 수있는 모든 작업을 수행 할 수 있습니까?
내가 찾은 문서 외에 샘플 / 튜토리얼 / 비디오가 있습니까?
2016 년 3 월 업데이트
으로 안드로이드 지원 라이브러리 23.2.1 업데이트 지원 벡터 드로어 블 Drawable 및 애니메이션 벡터 드로어 블 Drawable. (동일하게 latestone을 사용할 수도 있습니다)
gradle 파일에서 라이브러리 버전을 업데이트하십시오.
compile 'com.android.support:recyclerview-v7:23.2.1'
벡터 드로어 블을 사용하면 여러 png 애셋을 XML로 정의 된 단일 벡터 그래픽 으로 바꿀 수 있습니다 . 이전 롤리팝 높은 장치로 제한하지만 , 모두 VectorDrawable
와 AnimatedVectorDrawable
이제 두 개의 새로운 지원 라이브러리를 통해 사용할 수 있습니다 지원 벡터 당김 및 애니메이션 벡터 당김. app:srcCompat
벡터 드로어 블을 참조하는 새로운 속성.
샘플 예제 와 함께 github 에서 소스를 확인하십시오 .
v7 appcompat 라이브러리의 변경 사항 :
벡터 자산에 대한 종속성을 되돌려 appcompat 라이브러리를 사용하는 개발자 VectorDrawable
가 관련 빌드 플래그 를 사용하지 않아도 됩니다.
이 지원 라이브러리를 사용해 볼 수 있습니다 . Lollipop에 도입 된 VectorDrawable 및 AnimatedVectorDrawable을 완벽하게 하위 호환성으로 지원합니다.
업데이트 2 : 지원 라이브러리 23.4.0에서 다시 활성화합니다.
AppCompat 사용자의 경우 AppCompatDelegate.setCompatVectorFromResourcesEnabled (true)를 통해 리소스 (23.2에서 발견 된 동작)에서 벡터 드로어 블 지원을 다시 활성화하는 옵트 인 API를 추가했습니다. 그래도 메모리 사용에 문제가 발생할 수 있습니다. 구성 인스턴스를 업데이트하는 데 문제가 있으므로 기본적으로 비활성화되어 있습니다.
업데이트 : 버전 23.3.0에서는 작동하지 않습니다 . 자세한 내용은 여기 를 확인 하세요 . 프록시 드로어 블이 작동하지 않습니다. app:srcCompat
및 setImageResource()
작업하지만.
벡터 드로어 블 지원은 버전 23.2 이상의 지원 라이브러리에서 사용할 수 있습니다. 그러나 이러한 드로어 블을 올바르게 사용하려면 간접적으로 참조해야합니다.
첫 번째 단계는 AppCompat
버전 을 높이는 것 입니다.
compile 'com.android.support:appcompat-v7:23.2.0'
두 번째로 Vector Drawable 지원을 활성화합니다. Gradle 플러그인을 사용하는 경우 2.0 이상
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
그렇지 않으면
android {
defaultConfig {
generatedDensities = []
}
aaptOptions {
additionalParameters "--no-version-vectors"
}
}
셋째 , 링크 된 답변을 참조하십시오 .
여기에 몇 가지 답변을 보완하기 위해 예, VectorDrawables pre-Lollipop에 대한 지원을 최소한 부분적으로 받을 수 있습니다 .
얼마나 부분적인가요? 도움 이 되도록 이 다이어그램 을 만들었습니다 (지원 라이브러리 23.4.0에서 최소-25.1.0까지 유효 함).
Unfortunately, at this point of time VectorDrawable and AnimatedVectorDrawable are not available in support library. But to avail this feature in Pre-Lollipop versions, you can use the unofficial backport called MrVector.
MrVector is available in Github and it will support android versions 7+.
From the official Readme
To add MrVector dependency add the following line to your build.gradle dependencies block.
compile 'com.telly:mrvector:0.2.0'
To create the drawable from the vector XML,
Drawable drawable = MrVector.inflate(getResources(), R.drawable.vector_android);
Hope this helps.
If you are using VectorDrawable, Android Studio will automatically generate according PNG files (based on your XML files) for Pre-Lollipop versions.
Note that those generated PNG files are considered BitmapDrawables instead of VectorDrawables on devices running API below 21 and therefore can't be animated or similar on those devices.
See "backwards compatibility" for further details: http://android-developers.blogspot.co.at/2015/09/android-studio-14.html
Lollipop cannot handle SVG files without third-party libs.
The best solution I found is the BetterVectorDrawable lib together with the SVG to VectorDrawable Converter.
BetterVectorDrawable is the VectorDrawable implementation for Android 4.0+ with configurable fall-back behavior on Android 5.0+.
SVG to VectorDrawable Converter is the batch converter of SVG images to Android VectorDrawable XML resource files. Online version
Links point to readmes, which provide enough information on how to use the lib and the converter.
There are no VectorDrawables in the support library at this time.
Funkystein is right -- VectorDrawable is similar to SVG, only supporting the features of vector drawing that are in highest demand so that android can focus on performance. pathData, for example has the same format as SVG's "d" string.
The great news is that Google released Android Support Library 23.2 Support Vector Drawables and Animated Vector Drawables!
But thanks go to the people who ported this library before Google!
This is where the AppCompat libraries are great, they can bring many of the new features of Android back to much earlier versions. With the newly implemented VectorDrawable class, developers can now use vector images all the way back to API 7 (Android 2.1 Eclair). Animated vectors are a bit more limited, going only as far back as API 11 (Android 3.0 Honeycomb), but that still encompasses more than 97% of devices in active use today
Guide to use:
Refer "age-of-the-vectors" by @chrisbanes
'development' 카테고리의 다른 글
React JS를 사용한 무한 스크롤 (0) | 2020.09.19 |
---|---|
정의되지 않은 동작 및 시퀀스 포인트가 다시로드 됨 (0) | 2020.09.19 |
.NET에서 SSIS 패키지를 실행하는 방법은 무엇입니까? (0) | 2020.09.19 |
Python에 Rake에 해당하는 것이 있습니까? (0) | 2020.09.19 |
String을 타입 클래스의 인스턴스로 만들 수없는 이유는 무엇입니까? (0) | 2020.09.19 |