以编程方式添加 ShaderImageView

Add ShaderImageView programmatically

我喜欢你运行这行代码

ShaderImageView imageview = new ShapeImageView(getBaseContext(), null, R.style.hexagonstyle);  
newphoto.setImageResource(R.drawable.image08);  
layout.addView(newphoto);

并得到这个错误:

Caused by: java.lang.RuntimeException: No resource is defined as shape

hexagone定义为

<style name="hexagonstyle">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="siBorderColor">@color/hexagoninnerborder</item>
    <item name="siBorderWidth">1dp</item>
    <item name="siShape">@raw/maskcopya</item>
</style>

依赖项:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.0.0'
    compile 'com.github.siyamed:android-shape-imageview:0.9.2@aar'
}

有关 ShapeImageView 的更多信息:https://github.com/siyamed/android-shape-imageview

如何以编程方式添加 ShapeImageView?也许 ShapeImageView() 的参数是错误的...

提前致谢!

反过来:

View view = LayoutInflater.from(this).inflate(R.layout.contactlist, null);
ImageView contactimage = (ImageView) view.findViewById(R.id.contactimage);

我将 ShaderImageView 放入 contactlist.xml 并在那里设置样式

已解决 :)