2017-07-15 45 views
0
<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" 
    android:paddingLeft="32dp" 
    android:paddingTop="10dp" 
    android:paddingRight="0dp" 
    android:paddingBottom="10dp"> 
    <item android:bottom="3dp"> 
     <bitmap 
      android:gravity="center_vertical|left" 
      android:src="@drawable/ic_publish_black_24dp" /> 
     <shape android:shape="rectangle"> 
      <stroke 
       android:width="0dp" 
       android:color="#37474f" /> 
     </shape> 
    </item> 
</layer-list> 

调整位图图像,这是我怎么称呼它:如何在Android的

TextView aboutBags = new TextView(mContext); 
aboutBags.setText("Compose"); 
aboutBags.setTextAppearance(R.style.RevStyleHelpAbout); 
aboutBags.setBackgroundResource(R.drawable.rev_item_h_border_left); 

我已经试过边界属性android:width="22dp" android:height="22dp"遍布XML,但图像没有得到调整。

如何调整位图图像大小?

Vielen dank im voraus。

回答

1

使用Bitmap可能会对您有所帮助。使用这样的:

Bitmap nameYourBitmap; 

Bitmap resized = Bitmap.createScaledBitmap(nameYourBitmap, newWidth, newHeight, true); 

你也可以这样做:

resized = Bitmap.createScaledBitmap(nameYourBitmap,(int)(nameYourBitmap.getWidth()*0.8), (int)(nameYourBitmap.getHeight()*0.8), true); 

请参阅本:How to resize Image in Android?

对于XML,规模属性为ScaleDrawables定义,并可以扩展其他绘制。请参考这个开发者网站:https://developer.android.com/guide/topics/resources/drawable-resource.html#Scale

+0

谢谢你的回复@Animesh Patra。我可以在XML中进行吗? –

+0

@ Program-Me-Rev欢迎您。如果我的回答有任何帮助,您可以接受它以备将来参考。 –