2
코드별로 다음 xml을 코딩하려고합니다.xml 레이어 목록을 코드로 레이어 드로 가능하게 변환하는 방법
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<bitmap android:src="@drawable/my_image"
android:gravity="left"/>
</item>
<item android:left="10dp">
<bitmap android:src="@drawable/my_image"
android:gravity="left" />
</item>
<item android:top="10dp">
<bitmap android:src="@drawable/my_image"
android:gravity="left"/>
</item>
<item android:top="10dp" android:left="10dp">
<bitmap android:src="@drawable/my_image"
android:gravity="left" />
</item>
<item android:top="20dp">
<bitmap android:src="@drawable/my_image"
android:gravity="left"/>
</item>
<item android:top="20dp" android:left="10dp">
<bitmap android:src="@drawable/my_image"
android:gravity="left" />
</item>
</layer-list>
---- 그리기 \의 my_layerdrawable.xml 난 다음 블록을 부호화하지만, 화상을 신장한다.
InsetDrawable[] layers = new InsetDrawable[this.itemCount];
Resources resources = getResources();
ImageButton imgButton = (ImageButton) findViewById(R.id.btnItems);
int layerTop = 0;
for (int i = 0; i < this.itemCount; i++)
{
int layerLeft = i % 2 == 1 ? 5 : 0;
Drawable dr = resources.getDrawable(R.drawable.my_image);
layers[i] = new InsetDrawable(dr, layerLeft, layerTop, -layerLeft, -layerTop);
layerTop += i % 2 == 1 ? 10 : 0;
}
LayerDrawable layerDrawable = new LayerDrawable(layers);
imgButton.setImageDrawable(layerDrawable);
내가 뭔가를 제대로 더 스트레치 또는 변경 작업되지 않는 imgButton
에 당김 XML을 할당
ImageButton imgButton = (ImageButton) findViewById(R.id.btnItems);
imgButton.setImageResource(R.drawable.my_layerdrawable);
코드로 드로어 블 레이어를 만들 수 있습니까?
감사합니다.