public class ATActivity extends Activity {
/** Called when the activity is first created. */
ImageView iv; android
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
iv = (ImageView) findViewById(R.id.iv);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.bottle_day_bg);
1.使用Bitmap的靜態方法 ide
// Bitmap smallBitmap = Bitmap.createBitmap(bitmap, 20, 20, 100, 100);
// iv.setImageBitmap(smallBitmap); spa
2.使用圖像剪切資源
ClipDrawable cl = (ClipDrawable) iv.getDrawable();
// 從圖像左側截取圖像的30%
cl.setLevel(3000); code
}
} xml
圖像剪切資源對應的xml ip
<?xml version="1.0" encoding="utf-8"?>
<clip xmlns:android="http://schemas.android.com/apk/res/android"
android:clipOrientation="horizontal"
android:drawable="@drawable/bottle_day_bg"
android:gravity="left" > utf-8
</clip> 資源