有人请尝试向我解释原因
public void addView(View child) {
child.setDrawingCacheEnabled(true);
child.setWillNotCacheDrawing(false);
child.setWillNotDraw(false);
child.buildDrawingCache();
if(child.getDrawingCache() == null) { //TODO Make this work!
Log.w("View", "View child's drawing cache is null");
}
setImageBitmap(child.getDrawingCache()); //TODO MAKE THIS WORK!!!
}
Run Code Online (Sandbox Code Playgroud)
ALWAYS记录绘图缓存为空,并将位图设置为null?
在设置缓存之前,我是否必须实际绘制视图?
谢谢!
基本上
在一个活动中,我有一个ListView.当我选择一个项目时,透明活动将作为一个小框打开.出现此框时,您仍然可以查看以前的活动屏幕,
我想弄清楚的是如何模糊前一个屏幕,就像这里链接的图像一样(忽略用户界面,只看模糊的草地区域).
这怎么可能?
谢谢你的任何建议.
我正在尝试给布局充气并使用它来在图像视图上设置位图.然后,我将该imageview添加到线性布局并显示线性布局.这是我尝试过的:
public class TestActivity extends Activity {
private static Bitmap bitMap;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout l = new LinearLayout(this);
bitMap = Bitmap.createBitmap(getWindowManager().getDefaultDisplay().getWidth(),
getWindowManager().getDefaultDisplay().getHeight(),
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitMap);
LayoutInflater inflater = LayoutInflater.from(this);
View v1 = inflater.inflate(R.layout.main, null);
v1.layout(0, 0, getWindowManager().getDefaultDisplay().getWidth(),
getWindowManager().getDefaultDisplay().getHeight());
v1.draw(canvas);
ImageView i1 = new ImageView(this);
i1.setImageBitmap(bitMap);
i1.setAdjustViewBounds(true);
i1.setLayoutParams(new FrameLayout.LayoutParams(getWindowManager().getDefaultDisplay().getWidth(),
getWindowManager().getDefaultDisplay().getHeight()));
l.addView(i1);
setContentView(l);
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,没有正确创建bitMap.有什么我做错了吗?
我正在使用以下行将视图转换为android中的位图.
view.setDrawingCacheEnabled(true);
Bitmap b= view.getDrawingCache();
Run Code Online (Sandbox Code Playgroud)
当我转换为Bitmap时,我在视图中有价值,它显示位图值null.
我需要创建一个自定义视图,然后将其保存到 png 文件到 sdcard 中。现在我在 sdcard 中得到黑色图像。我无法在代码中找出问题。任何人都可以帮助我。
布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:orientation="vertical" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/black" />
<TextView
android:id="@+id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/black" />
</LinearLyout>
Run Code Online (Sandbox Code Playgroud)
在我的 java 文件中,我膨胀了线性布局并将数据设置为 textviews,然后我调用:
private Bitmap convertViewToBitmap(LinearLayout layout) {
layout.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
int width = layout.getMeasuredWidth();
int height = layout.getMeasuredHeight();
//Create the bitmap
Bitmap bitmap = Bitmap.createBitmap(width,
height,
Bitmap.Config.ARGB_8888);
//Create a canvas with the specified bitmap to draw into
Canvas c = new Canvas(bitmap);
//Render this view (and all of …Run Code Online (Sandbox Code Playgroud)