2016-04-15 72 views
1

我想將佈局轉換爲位圖。該佈局包含Textview和Listview。文本視圖顯示在位圖中,但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

在setAdapter()調用之後立即調用'itl1.notifyDataSetChanged()',或者項目顯示正確但不顯示在繪圖緩存中? – Guardanis

+0

yes項目正在顯示,但未顯示在繪圖緩存中。 –

回答

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