2011-10-17 12 views
0

現在、スクリーンショットを取得して添付ファイルとして電子メールを送信するアプリを開発中です。次の「LinearLayout」のスクリーンショットが必要です。適切なスクリーンショットを取得できません

しかし、この関数を呼び出すと、非常に奇妙なことが起こっています。レイアウト全体のスクリーンショットを撮るのではなく、スクリーンショットの約1/10しか撮られません(最初の列の半分のように)。誰もがここにコードが間違っていることをお勧めしますか?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/tableview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:weightSum="1" 
    android:orientation="vertical" > 

<TableLayout android:padding="5dp" 
     android:layout_width="match_parent" 
     android:id="@+id/TransactionLog"  
     android:layout_height="wrap_content"> 

     <TableRow android:layout_height="wrap_content"> 
      <TextView android:layout_margin="4dip" 
         android:layout_weight="1" 
         android:padding="10dip" 
         android:layout_height="wrap_content" 
         android:text="Date" 
         android:layout_width="0dip" 
         android:id="@+id/dateLabel" /> 
      <TextView android:layout_margin="4dip" 
         android:layout_weight="1" 
         android:padding="10dip" 
         android:layout_height="wrap_content" 
         android:text="Details" 
         android:layout_width="0dip" 
         android:id="@+id/detailsLabel" /> 
      <TextView android:layout_margin="4dip" 
         android:layout_weight="1" 
         android:padding="10dip" 
         android:layout_height="wrap_content" 
         android:text="Debit" 
         android:layout_width="0dip" 
         android:id="@+id/debitLabel" /> 
      <TextView android:layout_margin="4dip" 
         android:layout_weight="1" 
         android:padding="10dip" 
         android:layout_height="wrap_content" 
         android:text="Credit" 
         android:layout_width="0dip" 
         android:id="@+id/creditLabel" /> 
      <TextView android:layout_margin="4dip" 
         android:layout_weight="1" 
         android:padding="10dip" 
         android:layout_height="wrap_content" 
         android:text="Balance" 
         android:layout_width="0dip" 
         android:id="@+id/balanceLabel" /> 
     </TableRow> 

     <TableRow android:layout_height="wrap_content"> 
      <TextView android:layout_margin="4dip" 
         android:layout_weight="1" 
         android:padding="10dip" 
         android:layout_height="wrap_content" 
         android:text="5 October 2011" 
         android:layout_width="0dip" 
         android:id="@+id/date1" /> 
      <TextView android:layout_margin="4dip" 
         android:layout_weight="1" 
         android:padding="10dip" 
         android:layout_height="wrap_content" 
         android:text="CoCoa Shop" 
         android:layout_width="0dip" 
         android:id="@+id/details1" /> 
      <TextView android:layout_margin="4dip" 
         android:layout_weight="1" 
         android:padding="10dip" 
         android:layout_height="wrap_content" 
         android:text="123.53" 
         android:layout_width="0dip" 
         android:id="@+id/debit1" /> 
      <TextView android:layout_margin="4dip" 
         android:layout_weight="1" 
         android:padding="10dip" 
         android:layout_height="wrap_content" 
         android:text="0.00" 
         android:layout_width="0dip" 
         android:id="@+id/credit1" /> 
      <TextView android:layout_margin="4dip" 
         android:layout_weight="1" 
         android:padding="10dip" 
         android:layout_height="wrap_content" 
         android:text="6729.32" 
         android:layout_width="0dip" 
         android:id="@+id/balance1" /> 
     </TableRow> 

     <TableRow android:layout_height="wrap_content"> 
      <TextView android:layout_margin="4dip" 
         android:layout_weight="1" 
         android:padding="10dip" 
         android:layout_height="wrap_content" 
         android:text="4 October 2011" 
         android:layout_width="0dip" 
         android:id="@+id/date1" /> 
      <TextView android:layout_margin="4dip" 
         android:layout_weight="1" 
         android:padding="10dip" 
         android:layout_height="wrap_content" 
         android:text="Best Sell" 
         android:layout_width="0dip" 
         android:id="@+id/details1" /> 
      <TextView android:layout_margin="4dip" 
         android:layout_weight="1" 
         android:padding="10dip" 
         android:layout_height="wrap_content" 
         android:text="900.53" 
         android:layout_width="0dip" 
         android:id="@+id/debit1" /> 
      <TextView android:layout_margin="4dip" 
         android:layout_weight="1" 
         android:padding="10dip" 
         android:layout_height="wrap_content" 
         android:text="0.00" 
         android:layout_width="0dip" 
         android:id="@+id/credit1" /> 
      <TextView android:layout_margin="4dip" 
         android:layout_weight="1" 
         android:padding="10dip" 
         android:layout_height="wrap_content" 
         android:text="6729.32" 
         android:layout_width="0dip" 
         android:id="@+id/balance1" /> 
     </TableRow> 

     <TableRow android:layout_height="wrap_content"> 
      <TextView android:layout_margin="4dip" 
         android:layout_weight="1" 
         android:padding="10dip" 
         android:layout_height="wrap_content" 
         android:text="4 October 2011" 
         android:layout_width="0dip" 
         android:id="@+id/date1" /> 
      <TextView android:layout_margin="4dip" 
         android:layout_weight="1" 
         android:padding="10dip" 
         android:layout_height="wrap_content" 
         android:text="Deposit" 
         android:layout_width="0dip" 
         android:id="@+id/details1" /> 
      <TextView android:layout_margin="4dip" 
         android:layout_weight="1" 
         android:padding="10dip" 
         android:layout_height="wrap_content" 
         android:text="0.00" 
         android:layout_width="0dip" 
         android:id="@+id/debit1" /> 
      <TextView android:layout_margin="4dip" 
         android:layout_weight="1" 
         android:padding="10dip" 
         android:layout_height="wrap_content" 
         android:text="9500.00" 
         android:layout_width="0dip" 
         android:id="@+id/credit1" /> 
      <TextView android:layout_margin="4dip" 
         android:layout_weight="1" 
         android:padding="10dip" 
         android:layout_height="wrap_content" 
         android:text="6729.32" 
         android:layout_width="0dip" 
         android:id="@+id/balance1" /> 
     </TableRow> 

</TableLayout> 

</LinearLayout> 

ここでは、スクリーンショットを撮ってSDカードの「ログ」というファイルに保存するJAVA関数を示します。

 private void getScreen() 
     { 
      View content = findViewById(R.id.tableview); 
      content.setDrawingCacheEnabled(true); 

      content.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), 
        MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); 

      content.layout(0, 0, content.getMeasuredWidth(), content.getMeasuredHeight()); 

      content.buildDrawingCache(true); 

      Bitmap bitmap = Bitmap.createBitmap(content.getDrawingCache()); 
      content.setDrawingCacheEnabled(false); // clear drawing cache 

      File file = new File(Environment.getExternalStorageDirectory() + "/log.png"); 

      try 
      { 
       file.createNewFile(); 
       FileOutputStream ostream = new FileOutputStream(file); 
       bitmap.compress(CompressFormat.PNG, 100, ostream); 
       ostream.close(); 

      } 
      catch (Exception e) 
      { 
       e.printStackTrace(); 
      } 

     } 
+1

はあなたに正しい寸法を与える)content.getMeasuredWidth()とcontent.getMeasuredHeight(いますか? – Martyn

+0

私はそれをチェックする方法を知らないことを恐れています... – BurninatorDor

+0

ログにダンプし、意味があるかどうかを確認しますか? – EightyEight

答えて

1

これらの行を削除AN再度試して、

content.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); 
content.layout(0, 0, content.getMeasuredWidth(), content.getMeasuredHeight()); 
関連する問題