<item android:left="10dp">
的等效java代码是什么?
更具体地说,我试图以编程方式获得一个等价于:
的Bitmap<item android:left="5dp" android:bottom="5dp">
<bitmap
android:src="@drawable/screw"
android:gravity="bottom|left" />
</item>
修改
到目前为止,我得到了:
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = false;
Bitmap screw = BitmapFactory.decodeResource(res, resId, options);
BitmapDrawable s = new BitmapDrawable(res, screw);
s.setGravity(Gravity.LEFT|Gravity.BOTTOM);
答案 0 :(得分:1)
您可以非常轻松地从xml中提升视图,或者如果您以编程方式加载drawable,则应使用文档:http://developer.android.com/reference/android/graphics/drawable/LayerDrawable.html
自从我使用java / android以来已经有一段时间了。但是这样。
Drawable[] layers = [drawable1, drawable2, etc]
LayerDrawable mDrawable = new LayerDrawable(layers);
//mDrawable.setLayerInset(int index, int left, int top, int right, int bottom)
//you will have to manually calculate density pixels.
mDrawable.setLayerInset(0, 5, 0, 0, 5)