2017-07-02 11 views
0

アンドロイドでdrawer xmlファイルを使用して作成したカスタムシェイプ内にイメージビューを表示したい。 Iv'eは結果を出さずに数週間インターネットを検索した。私が見つけた唯一の答えは、通常の図形(円、矩形)を使ったりレイヤーでxmlを使用しています(画像を背景として置く)が、画像はサーバーから動的です。イメージビューをカスタム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

で、この問題を解決する唯一の方法は、2つの要素を含んで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同じ大きさ(幅と高さ)を持っている必要があります

+0

こんにちは@Karimは返事をありがとう、 Elidotnet

+0

これはxmlのカスタムシェイプを表します。 – Karim

関連する問題