我正在尝试将布局转换为位图。布局包含Textview和Listview。 Textview正在Bitmap中显示,但Listview正在显示但未在绘图缓存中显示(显示为空)。这是我的代码
Print.xml
<LinearLayout
android:id="@+id/screen_print1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/tax_amnt"
android:layout_width="360dp"
android:layout_height="wrap_content"
android:gravity="right"
android:text="Tax : $200" />
<ListView
android:id="@+id/item_listview1"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_gravity="center" />
</LinearLayout>
Print.java
LinearLayout screenshot = (LinearLayout) findViewById(R.id.screen_print1);
ListView items_display=(ListView)findViewById(R.id.item_listview1);
TextView tax_amount=(TextView)findViewById(R.id.tax_amnt);
tax_amount.setText("$5000");
ArrayList<HashMap<String, String>> bill_list1=OrderSummaryFragment.item_lists;
itl1 = new Itemlist(getApplicationContext(), bill_list1);
items_display.setAdapter(itl1);
screenshot.setDrawingCacheEnabled(true);
screenshot.buildDrawingCache();
Bitmap bm = screenshot.getDrawingCache();
screen_imageview.setImageBitmap(bm);
答案 0 :(得分:0)
更新行
screenshot.setDrawingCacheEnabled(true);
screenshot.buildDrawingCache();
以强>
screenshot.setDrawingCacheEnabled(true);
screenshot.measure(View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED),View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
screenshot.layout(0, 0, screenshot.getMeasuredWidth(), screenshot.getMeasuredHeight());
screenshot.buildDrawingCache(true);