我正在尝试以编程方式创建九个补丁映像。我已经尝试了Griffey's方法,但似乎不能让它工作。关于如何使用这个类的信息很少。我认为我导入的位图不正确。如果有人知道如何让它工作,或者知道更好的方法,我将非常感谢您的帮助。
我的代码:
// Dynamically create the 9patch image and apply it to a LinearLayout
LinearLayout llcode = (LinearLayout) findViewById(R.id.llcode);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.white_button);
Drawable np = NinePatchBitmapFactory.createNinePathWithCapInsets(getResources(), bitmap, 15, 15, 16, 16, null);
llcode.setBackgroundDrawable(np);
// The following code using the actual 9patch image: white_button_np.9.png
LinearLayout llxml = (LinearLayout) findViewById(R.id.llxml);
llxml.setBackgroundDrawable(getResources().getDrawable(R.drawable.white_button_np));
此屏幕截图显示了顶部的编程方法和底部使用android工具的典型9patch方法。
转换为9补丁之前的原始图像。
发布于 2013-01-22 20:00:04
你有没有尝试过强制解码器配置,以确保有一个alpha通道?
尝试将inPreferredConfig设置为ARGB_8888。
发布于 2014-01-20 21:14:59
解决方案在这里:https://stackoverflow.com/a/16676419/238845。我已经在API level 10仿真器上成功地测试了它。
https://stackoverflow.com/questions/14442011
复制相似问题