2013-08-29 68 views
0

我想在android中創建textview的鏡像圖像。我想下面的代碼,但它不工作如何在Android中創建textview的鏡像圖像?

我的代碼如下: -

public class MainActivity extends Activity { 
TextView tv; 
ImageView myImageView; 
Bitmap bmp; 
int bmpWidth, bmpHeight; 

Matrix matrixMirrorY; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     tv=(TextView)findViewById(R.id.tv1); 

     tv.buildDrawingCache(); 
     bmp=Bitmap.createBitmap(tv.getDrawingCache()); 

     Matrix matrix = new Matrix(); 
     matrix.preScale(-1.0f, 1.0f); 
     Bitmap mirroredBitmap = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, false); 
     myImageView.setImageBitmap(mirroredBitmap);   
      }  

    } 

回答

0
public class MainActivity extends Activity { 
TextView tv; 
ImageView myImageView; 
Bitmap bmp; 
int bmpWidth, bmpHeight; 

Matrix matrixMirrorY; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     tv=(TextView)findViewById(R.id.textView1); 
     myImageView=(ImageView)findViewById(R.id.imageView1); 
     tv.setDrawingCacheEnabled(true); 
     tv.buildDrawingCache(); 
     bmp=Bitmap.createBitmap(tv.getDrawingCache()); 

     Matrix matrix = new Matrix(); 
     matrix.preScale(-1.0f, 1.0f); 
     Bitmap mirroredBitmap = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, false); 
     myImageView.setImageBitmap(mirroredBitmap);   
      }  

    }