編輯:關於Android編程
首先通過ddms把圖片導入模擬器
package com.example.testimageview;
import java.io.FileNotFoundException;
import java.io.IOException;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.support.v4.widget.SimpleCursorAdapter.ViewBinder;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
public class MainActivity extends Activity implements OnClickListener
{
private Button bclick;
private ImageView imageView;
private SeekBar sBar;
private Bitmap bmp;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bclick = (Button) findViewById(R.id.bclick);
bclick.setOnClickListener(this);
imageView = (ImageView) findViewById(R.id.image_view);
sBar = (SeekBar) findViewById(R.id.sb);
sBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
{
@Override
public void onStopTrackingTouch(SeekBar seekBar)
{
// TODO Auto-generated method stub
}
@Override
public void onStartTrackingTouch(SeekBar seekBar)
{
// TODO Auto-generated method stub
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser)
{
// TODO Auto-generated method stub
//創建一個與取出來的圖片大小一致的位圖文件
Bitmap alterBmp = bmp.createBitmap(bmp.getWidth(), bmp.getHeight(), bmp.getConfig());
//畫布
Canvas canvas = new Canvas(alterBmp);
//畫筆
Paint paint = new Paint();
paint.setStrokeWidth(5f);
//矩陣....
Matrix matrix = new Matrix();
// scale 縮放 rotate 旋轉translate 平移
//matrix.setRotate((float) 0.9*progress);
//matrix.setScale(0.1f*progress,0.1f*progress);
matrix.setTranslate(-0.1f*progress,-0.1f*progress);
canvas.drawBitmap(bmp, matrix, paint);
imageView.setImageBitmap(alterBmp);
}
});
}
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.setAction(Intent.ACTION_PICK);
intent.setType("image/*");
//startActivity(intent);
startActivityForResult(intent, 1);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
// TODO Auto-generated method stub
if(requestCode==1)
{
if(resultCode == RESULT_OK)
{
try
{
Uri uri = data.getData();
bmp =MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
imageView.setImageURI(uri);
} catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
shape_rectangle.xml shape_oval.xml shape_line.xml
上一篇我們說到的逐幀動畫和補間動畫,這篇我們著重說下屬性動畫:先看下面兩幅動畫: 上面兩幅動畫就是通過屬性動畫做出來的,是不是比較炫呢!不僅有顯示,也有交互點擊事件。下面
ListView是android中最常用的控件之一。 在實際運用中往往會遇到一次性加載全部數據過多,需要分頁加載增加程序運行效率! 本demo是將更新的監聽放在listv
一、效果圖 二、代碼 復制代碼 代碼如下: public class TextSubView extends TextView { private TextPaint m