Android 如何将动态背景图像放入框架布局中
我想提前谢谢你。我是新开发安卓应用程序的人(事实上,这是我的第一个安卓应用程序)。在应用程序中,我让用户选择他/她的一张照片,并将其作为背景。我收集图像并使用putExtra方法将其发送到适当的活动 这是我处理图像的方式:Android 如何将动态背景图像放入框架布局中,android,image,layout,dynamic,background,Android,Image,Layout,Dynamic,Background,我想提前谢谢你。我是新开发安卓应用程序的人(事实上,这是我的第一个安卓应用程序)。在应用程序中,我让用户选择他/她的一张照片,并将其作为背景。我收集图像并使用putExtra方法将其发送到适当的活动 这是我处理图像的方式: protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 0){ Uri selectedIm
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 0){
Uri selectedImage = data.getData();
InputStream is;
try {
is = getContentResolver().openInputStream(selectedImage);
BufferedInputStream bis = new BufferedInputStream(is);
Bitmap imagen = BitmapFactory.decodeStream(bis);
final float densityMultiplier = getResources().getDisplayMetrics().density;
int h= (int) (100*densityMultiplier);
int w= (int) (h * imagen.getWidth()/((double) imagen.getHeight()));
imagen=Bitmap.createScaledBitmap(imagen, w, h, true);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
imagen.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] b = baos.toByteArray();
imagenCodificada = Base64.encodeToString(b, Base64.DEFAULT);
}
catch (FileNotFoundException e) {}
}
}
我是这样发送的:
i.putExtra("Preferencia5", imagenCodificada)
在活动中,我将图像反编码为位图,但我不知道如何将其作为背景放到框架布局中
在活动中:
byte[] b = Base64.decode(imagen, Base64.DEFAULT);
Bitmap imDecodificada = BitmapFactory.decodeByteArray(b, 0, b.length);
这是我的布局的.xml的开始:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/framelayout">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
非常感谢。使用layout.setBackgroundDrawable和BitmapDrawable参数Hi-pskink,但是我有一个问题(事实上非常愚蠢)我如何获得变量“layout”?谢谢FindViewById(R.id.framelayout)非常感谢,它工作得非常完美。我还有一个问题,我知道这不是线程的主题,但是,你知道如何获取用户的电话背景并将其放入活动背景中吗?非常感谢。没有“用户电话背景”这样的东西,因为每个用户都可以有不同的HomeLauncher应用程序