2

这是层列表,名为 index.xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
	<item android:id="@+id/ll_23_1015_0" android:top="0dp" android:left="0dp" android:bottom="0dp" android:right="0dp">
        <shape android:shape="rectangle">
            <size android:width="1205dp" android:height="1795dp"/>
            <solid android:color="#FFF"/>
        </shape>
    </item>
    <item android:id="@+id/ll_23_1015_1" android:top="75dp" android:left="50dp" android:bottom="1366dp" android:right="919dp">
		<bitmap android:src="@drawable/pic_23" />
    </item>
        <item android:id="@+id/ll_23_1015_2" android:top="504dp" android:left="50dp" android:bottom="937dp" android:right="919dp">
		<bitmap android:src="@drawable/pic_23" />
    </item>
        <item android:id="@+id/ll_23_1015_3" android:top="933dp" android:left="50dp" android:bottom="508dp" android:right="919dp">
		<bitmap android:src="@drawable/pic_23" />
    </item>
        <item android:id="@+id/ll_23_1015_4" android:top="1362dp" android:left="50dp" android:bottom="79dp" android:right="919dp">
		<bitmap android:src="@drawable/pic_23" />
    </item>
 </layer-list>

这是我的代码:

    imgVShare = (ImageView) findViewById(R.id.imgVShare);
    String path = "/storage/sdcard0/temp_photo.jpg";
    Drawable finalPic = Drawable.createFromPath(path);

            LayerDrawable myDrawable= (LayerDrawable)getResources().getDrawable(R.drawable.index);
    for(int i=0; i<5; i++) 
        {
         String ID = "ll_23_1015_" + (i+1);
         int resID = getResources().getIdentifier(ID, "id", getPackageName());
         Drawable layer =  myDrawable.findDrawableByLayerId(resID);
         layer = finalPic;
         myDrawable.setDrawableByLayerId(resID, layer);
        }
        imgVShare.setImageDrawable(myDrawable);

我想做的就是用内部存储上的“temp_photo.jpg”替换图层列表中的所有位图。此方法只是替换最后一个位图并清除其余部分.....请帮助....!

4

0 回答 0