<item android:left="10dp">的等效java代码是什么?
更确切地说,我正试图从程序上获得一个比特图,它相当于:
<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);发布于 2013-03-11 07:19:14
您可以很容易地从xml中膨胀视图,或者如果您正在以编程方式加载可绘图,则应该使用文档: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)https://stackoverflow.com/questions/15331632
复制相似问题