2017-07-15 28 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歡迎您。如果我的回答有任何幫助,您可以接受它以備將來參考。 –