无法将Listview转换为位图

时间:2016-04-15 14:15:50

标签: android bitmap android-bitmap bitmapimage

我正在尝试将布局转换为位图。布局包含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);

1 个答案:

答案 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);