Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 能否将矢量可绘制路径数据转换为路径对象_Android_Vector - Fatal编程技术网

Android 能否将矢量可绘制路径数据转换为路径对象

Android 能否将矢量可绘制路径数据转换为路径对象,android,vector,Android,Vector,是否可以将pathData从VectorDrawable中拉出,并将其转换为Path对象 我想创建一个自定义的ViewOutlineProvider,并为其提供一个任意形状来剪裁和投射阴影。如果有一种方法可以直接使用VectorDrawable,那就更好了 谢谢, ndh “Android可以将->转换为 安卓。图形 介绍 我们需要: 从XML解析以查找 从XML膨胀到视图类(或子类、ImageView等) 转换为类(使用) 在github中有一个可以完成所有工作的 给你 只需在应用程序的b

是否可以将
pathData
VectorDrawable
中拉出,并将其转换为
Path
对象

我想创建一个自定义的
ViewOutlineProvider
,并为其提供一个任意形状来剪裁和投射阴影。如果有一种方法可以直接使用
VectorDrawable
,那就更好了

谢谢, ndh

“Android可以将->转换为 安卓。图形

介绍 我们需要:

  • 从XML解析以查找
  • 从XML膨胀到
    视图
    类(或子类、ImageView等)
  • 转换为类(使用)
github中有一个可以完成所有工作的

给你

只需在应用程序的
build.gradle
中添加以下依赖项(请参见附带的示例应用程序):

下面是使用它的我的测试应用程序的图像:

安装程序 下面是一个要使用的向量(pathData)…res\drawable\ic\u heart.xml

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:name="outline"
        android:pathData="M20.84,4.61a5.5,5.5 0,0 0,-7.78 0L12,5.67l-1.06,-1.06a5.5,5.5 0,0 0,-7.78 7.78l1.06,1.06L12,21.23l7.78,-7.78 1.06,-1.06a5.5,5.5 0,0 0,0 -7.78z"
        android:strokeLineCap="round"
        android:strokeColor="#5D5D5D"
        android:fillColor="#00000000"
        android:strokeWidth="2"
        android:strokeLineJoin="round"/>
</vector>
<com.sdsmdg.harjot.vectormaster.VectorMasterView
    android:id="@+id/heart_vector"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:layout_margin="10dp"
    android:scaleX="0.8"
    android:scaleY="0.8"
    app:vector_src="@drawable/ic_heart" />
代码 在
onCreate
中设置
向量

//normal stuff
setContentView(R.layout.activity_main);

//Inflate the `Vector`
VectorMasterView vmHeartVector = (VectorMasterView) findViewById(R.id.heart_vector);

// find the correct path using name
PathModel outline = vmHeartVector.getPathModelByName("outline");

String pathData   = outline.getPathData();// this is our pathData
Path   path       = outline.getPath();    // this is our path object;
一些链接: , , , , , ,
.

对于那些正在查找pathData->Path conversion的用户,这里是:
//normal stuff
setContentView(R.layout.activity_main);

//Inflate the `Vector`
VectorMasterView vmHeartVector = (VectorMasterView) findViewById(R.id.heart_vector);

// find the correct path using name
PathModel outline = vmHeartVector.getPathModelByName("outline");

String pathData   = outline.getPathData();// this is our pathData
Path   path       = outline.getPath();    // this is our path object;