⑴ Android动态添加自定义控件(照片装饰素材)canvas 画板相关问题!求帮助!
点击的时候获取到整个父布局(你添加自定义view的父布局),隐藏或者移除不是点击的这个组件就好了啊,如果不好确定父布局里面哪个是点击的空间,那就给每个控制设置id就可以了
⑵ android gallery如何动态添加图片 Integer[] images = { R.drawable.1,R.drawable.2} 这是我写死的数组
拍照调用camera.takePicture(shutter, pc1, pc2)方法;
我们可以第3个参数中处理一下。
private PictureCallback pc2 = new PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
// TODO Auto-generated method stub
// 存储相片-Decode an immutable(不变的) bitmap from the specified byte
// array.
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
FileOutputStream out = null;
try {
out = new FileOutputStream("/sdcard/pic_1.jpg");
BufferedOutputStream bos = new BufferedOutputStream(out);
bitmap.compress(CompressFormat.JPEG, 80, bos);// 压缩图片
bos.flush();
bos.close();
out.close();
iv.setImageBitmap(bitmap);//iv是一个imageView
stopCamera();// 关闭照相机
init();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
⑶ 安卓中如何添加显示gif动态图片
大家都知道,Android开发模拟器为了节省内存,一般不支持直接显示gif图片,即使你强制设置了,也只会显示图片的第一帧。看到网上也有许多的方法,来实现此功能,可都比较的繁琐,需要修改android源代码来实现或者用gif解析器来实现。在此文章中,这里教大家一种比较简洁的一个方法,你可以把这个类当做是一种工具类。用的时候,直接搬到程序里面,更改下图片的资源,就可以非常轻松的显示gif图片了。
步骤1:看一下这个工具类的实例代码:MyGifView.java
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Movie;
import android.util.AttributeSet;
import android.view.View;
public class MyGifView extends View{
private long movieStart;
private Movie movie;
//此处必须重写该构造方法
public MyGifView(Context context,AttributeSet attributeSet) {
super(context,attributeSet);
//以文件流(InputStream)读取进gif图片资源
movie=Movie.decodeStream(getResources().openRawResource(R.drawable.keyboard));
}
@Override
protected void onDraw(Canvas canvas) {
long curTime=android.os.SystemClock.uptimeMillis();
//第一次播放
if (movieStart == 0) {
movieStart = curTime;
}
if (movie != null) {
int raction = movie.ration();
int relTime = (int) ((curTime-movieStart)%raction);
movie.setTime(relTime);
movie.draw(canvas, 0, 0);
//强制重绘
invalidate();
}
super.onDraw(canvas);
}
}
此工具类中,只做了2件事情。1,构造方法;2,重写了onDraw()方法。大家以后用的话,只需拷贝此类到你的工程下即可起作用。
步骤2:布局文件代码 activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:text="====Gif图片测试布局===="
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
<com.example.showgifimage.MyGifView
android:id="@+id/iv"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_margin="20dp"
/>
</LinearLayout>
布局文件中,注意的是:标签的设置 <com.example.showgifimage.MyGifView/>.
格式:包名+.类名
步骤3:主activity中调用
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
就这么轻松的把Gif图片显示了~~
⑷ android中怎么实现动态设置背景图片的功能,我在网上搜到的只能设置到当前的页面,并不能实现设置到全部
当关闭重新运行,它又会自动跳回原始的背景图片。
在开发过程中,由于使用模拟器测试了程序,在首次运行后会将res文件夹下的图片资源文件(如drawable-hdpi、drawable-ldpi和drawable-mdpi)拷贝到bin文件夹下。在替换资源图片后,eclipse并不清楚是否有图片改变,所以会使用原来bin下的res文件夹中的资源文件进行打包,而图片用的还是第一次eclipse所拷贝进去的文件,所以当运行程序后会发现替换资源图片在程序中没起作用。
解决办法:每次运行前,清理项目

动态设置背景图片代码
privateinti=0;//全局变量定义,初始化
//list数组接收到从文件中读取到的数据
List<String>list=readTxt.getDierguanResource();
//changeBack这个函数用来动态设置背景图片
publicvoidchangeBack(intbackground){
main=(LinearLayout)findViewById(R.id.shizi);
Stringa=list.get(background);
//获取到的背景图片名as(图片存到res/drawable文件下)
Stringas=a.split("")[1];
//动态获取图片getResources().getIdentifier(as,"drawable",getPackageName())
intresID=getResources().getIdentifier(as,"drawable",getPackageName());
//设置页面背景setBackgroundResource()
main.setBackgroundResource(resID);
}
if(i>=0&&i<list.size()){
changeBack(i);
}
⑸ android 存在数据库中的动态图片,如何读取出来,显示在ImageView中
实现的功能为从服务器获取图片数据,在布局页面上显示。由于图片的个数是不确定的,因此采用在布局页面中定义多个ImageView来显示图片是不合理的。
(一)首先定义布局
android:id="@+id/id_layout_movie"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
(二)加载图片显示时获取到布局文件
RelativeLayout rl_Movie = (RelativeLayout) findViewById(R.id.id_layout_movie);
(三)依次循环服务器获取的图片数据,一张一张设置图片显示的位置
//newWidth为图片显示的宽度,newHeight为图片显示的高度
RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams( newWidth, newHeight);
设置lp1.leftMargin和lp1.topMargin的值
(四)最后设置rl_Movie.addView(iv, lp1)将图片加入布局文件中