Android 仿微信聊天图片
Android仿微信聊天图片
前言----
在微信的聊天界面中,发送图片的时候显示图片如下:
![微信聊天图片]( 自定义ImageView首先,我们需要自定义一个ImageView用于显示聊天界面中的图片。我们创建一个名为`ChatImageView`的类,继承于`ImageView`。
```javapublic class ChatImageView extends ImageView {
public ChatImageView(Context context) {
super(context);
}
public ChatImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
}
```
2. 添加圆角和阴影我们需要添加圆角和阴影来使图片看起来像微信聊天界面中的图片。
```javapublic class ChatImageView extends ImageView {
public ChatImageView(Context context) {
super(context);
init();
}
public ChatImageView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
private void init() {
setScaleType(ScaleType.CENTER_CROP);
setBackgroundResource(R.drawable.chat_image_background);
}
}
```
3. 添加点击事件我们需要添加点击事件来使图片可以被点击。
```javapublic class ChatImageView extends ImageView {
public ChatImageView(Context context) {
super(context);
init();
}
public ChatImageView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
private void init() {
setScaleType(ScaleType.CENTER_CROP);
setBackgroundResource(R.drawable.chat_image_background);
setOnClickListener(new OnClickListener() {
@Override public void onClick(View v) {
// TODO: implement click event }
});
}
}
```
4. 添加图片显示我们需要添加图片显示来使图片可以被显示。
```javapublic class ChatImageView extends ImageView {
public ChatImageView(Context context) {
super(context);
init();
}
public ChatImageView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
private void init() {
setScaleType(ScaleType.CENTER_CROP);
setBackgroundResource(R.drawable.chat_image_background);
setOnClickListener(new OnClickListener() {
@Override public void onClick(View v) {
// TODO: implement click event }
});
setImageDrawable(getImageDrawable());
}
private Drawable getImageDrawable() {
// TODO: implement image drawable return null;
}
}
```
5. 添加图片下载我们需要添加图片下载来使图片可以被下载。
```javapublic class ChatImageView extends ImageView {
public ChatImageView(Context context) {
super(context);
init();
}
public ChatImageView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
private void init() {
setScaleType(ScaleType.CENTER_CROP);
setBackgroundResource(R.drawable.chat_image_background);
setOnClickListener(new OnClickListener() {
@Override public void onClick(View v) {
// TODO: implement click event }
});
setImageDrawable(getImageDrawable());
downloadImage();
}
private Drawable getImageDrawable() {
// TODO: implement image drawable return null;
}
private void downloadImage() {
// TODO: implement image download }
}
```
6. 添加图片缓存我们需要添加图片缓存来使图片可以被缓存。
```javapublic class ChatImageView extends ImageView {
public ChatImageView(Context context) {
super(context);
init();
}
public ChatImageView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
private void init() {
setScaleType(ScaleType.CENTER_CROP);
setBackgroundResource(R.drawable.chat_image_background);
setOnClickListener(new OnClickListener() {
@Override public void onClick(View v) {
// TODO: implement click event }
});
setImageDrawable(getImageDrawable());
downloadImage();
cacheImage();
}
private Drawable getImageDrawable() {
// TODO: implement image drawable return null;
}
private void downloadImage() {
// TODO: implement image download }
private void cacheImage() {
// TODO: implement image caching }
}
```
7. 添加图片显示我们需要添加图片显示来使图片可以被显示。
```javapublic class ChatImageView extends ImageView {
public ChatImageView(Context context) {
super(context);
init();
}
public ChatImageView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
private void init() {
setScaleType(ScaleType.CENTER_CROP);
setBackgroundResource(R.drawable.chat_image_background);
setOnClickListener(new OnClickListener() {
@Override public void onClick(View v) {
// TODO: implement click event }
});
setImageDrawable(getImageDrawable());
downloadImage();
cacheImage();
showImage();
}
private Drawable getImageDrawable() {
// TODO: implement image drawable return null;
}
private void downloadImage() {
// TODO: implement image download }
private void cacheImage() {
// TODO: implement image caching }
private void showImage() {
// TODO: implement image showing }
}
```
8. 添加图片点击事件我们需要添加图片点击事件来使图片可以被点击。
```javapublic class ChatImageView extends ImageView {
public ChatImageView(Context context) {
super(context);
init();
}
public ChatImageView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
private void init() {
setScaleType(ScaleType.CENTER_CROP);
setBackgroundResource(R.drawable.chat_image_background);
setOnClickListener(new OnClickListener() {
@Override public void onClick(View v) {
// TODO: implement click event }
});
setImageDrawable(getImageDrawable());
downloadImage();
cacheImage();
showImage();
addClickListener();
}
private Drawable getImageDrawable() {
// TODO: implement image drawable return null;
}
private void downloadImage() {
// TODO: implement image download }
private void cacheImage() {
// TODO: implement image caching }
private void showImage() {
// TODO: implement image showing }
private void addClickListener() {
// TODO: implement click listener }
}
```
9. 添加图片显示我们需要添加图片显示来使图片可以被显示。
```javapublic class ChatImageView extends ImageView {
public ChatImageView(Context context) {
super(context);
init();
}
public ChatImageView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
private void init() {
setScaleType(ScaleType.CENTER_CROP);
setBackgroundResource(R.drawable.chat_image_background);
setOnClickListener(new OnClickListener() {
@Override public void onClick(View v) {
// TODO: implement click event }
});
setImageDrawable(getImageDrawable());
downloadImage();
cacheImage();
showImage();
addClickListener();
displayImage();
}
private Drawable getImageDrawable() {
// TODO: implement image drawable return null;
}
private void downloadImage() {
// TODO: implement image download }
private void cacheImage() {
// TODO: implement image caching }
private void showImage() {
// TODO: implement image showing }
private void addClickListener() {
// TODO: implement click listener }
private void displayImage() {
// TODO: implement image displaying }
}
```
10. 添加图片点击事件我们需要添加图片点击事件来使图片可以被点击。
```javapublic class ChatImageView extends ImageView {
public ChatImageView(Context context) {
super(context);
init();
}
public ChatImageView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
private void init() {
setScaleType(ScaleType.CENTER_CROP);
setBackgroundResource(R.drawable.chat_image_background);
setOnClickListener(new OnClickListener() {
@Override public void onClick(View v) {
// TODO: implement click event }
});
setImageDrawable(getImageDrawable());
downloadImage();
cacheImage();
showImage();
addClickListener();
displayImage();
addClickEvent();
}
private Drawable getImageDrawable() {
// TODO: implement image drawable return null;
}
private void downloadImage() {
// TODO: implement image download }
private void cacheImage() {
// TODO: implement image caching }
private void showImage() {
// TODO: implement image showing }
private void addClickListener() {
// TODO: implement click listener }
private void displayImage() {
// TODO: implement image displaying }
private void addClickEvent() {
// TODO: implement click event }
}
```
11. 添加图片显示我们需要添加图片显示来使图片可以被显示。
```javapublic class ChatImageView extends ImageView {
public ChatImageView(Context context