2017-07-02 21 views
0

我想显示使用抽屉XML文件中的android创建自定义形状内部ImageView的。 Iv'e在网上搜索了几个星期,但没有结果。我找到的唯一答案是使用常规形状(圆形,矩形)或在图层中使用xml(将图像作为背景),但图像是从服务器动态显示的。如何插入的ImageView到自定义XML形状

这是图像视图

<ImageView 
    android:layout_width="200dp" 
    android:layout_height="200dp" 
    android:scaleType="centerCrop" 
    app:srcCompat="@drawable/upload_newdish_icon" 
    android:layout_below="@+id/dish_name_et" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="20dp" 
    android:id="@+id/imageView2" /> 

这是自定形状

<?xml version="1.0" encoding="utf-8"?> 
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="70dp" android:height="70dp" android:viewportHeight="700.000000" android:viewportWidth="700.000000"> 

<group android:scaleX="0.100000" android:scaleY="-0.100000" android:translateY="700.000000"> 
<path android:fillColor="@color/colorPrimary" android:pathData="M3065 6779 c-632 -31 -1270 -127 -1895 -285 -274 -70 -351 -105 -455 -209 -104 -104 -139 -181 -209 -455 -145 -574 -232 -1117 -278 -1745 -19 -256 -16 -979 6 -1245 46 -580 135 -1128 271 -1665 71 -280 105 -355 210 -460 104 -104 181 -139 455 -209 544 -137 1088 -226 1670 -273 301 -24 1019 -24 1320 0 582 47 1126 136 1670 273 274 70 351 105 455 209 104 104 139 181 209 455 145 574 232 1117 278 1745 19 256 16 979 -6 1245 -46 580 -135 1128 -271 1665 -71 280 -105 355-210 460 -104 104 -181 139 -455 209 -914 231 -1864 329 -2765 285z"/> 
</group> 
</vector> 
+0

添加一些代码,你做了什么这么远吗? – jagapathi

回答

0

来解决这个问题的唯一方法是使用FrameLayout里包含两个要素:您的自定义形状和包含图像视图的相关图层

<FrameLayout> 

<Custom_shape 
android:layout_width="xdp" 
android:layout_height="ydp" 
> 

<RelativeLayout 
android:layout_width="xdp" 
android:layout_height="ydp"> 

<imageview 
centerinparent="true" 
//dimension of the image view (should <(x,y)) 
//or set wrap content for the widh and the height + set a padding to get the imageview in the center of relativelayout 

> 

</RelativeLayout> 

</FrameLayout> 

自定义形状和RelativeLayout s HOULD具有相同的尺寸(宽度和高度)

+0

你好@Karim感谢答复,是什么 Elidotnet

+0

它代表您在xml中的自定义形状。 – Karim