Android 在ImageView上设置文本
我有一个android应用程序,我用照相手机拍了一张照片…然后把照片放在Android 在ImageView上设置文本,android,imageview,Android,Imageview,我有一个android应用程序,我用照相手机拍了一张照片…然后把照片放在图像视图中 到目前为止,我已经做了如下工作: ImageView image; bitmap = android.provider.MediaStore.Images.Media .getBitmap(cr, selectedImage); image.setImageBitmap(bitmap); 你能帮我告诉我下一步该做什么吗?一些代码会很好 编辑:XML
图像视图中
到目前为止,我已经做了如下工作:
ImageView image;
bitmap = android.provider.MediaStore.Images.Media
.getBitmap(cr, selectedImage);
image.setImageBitmap(bitmap);
你能帮我告诉我下一步该做什么吗?一些代码会很好
编辑:XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1">
<Button
android:id="@+id/logoButton"
android:layout_height="wrap_content"
android:text="LogoButton"
android:layout_marginLeft="40dip"
android:layout_width="224dp">
</Button>
<ImageView
android:id="@+id/imageview"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
</ImageView>
1.我不确定FrameLayout的这个技巧是否会将文本放在我的图像上…因为我更想上传照片。如果我将照片上传到网站上,文本还会存在吗
2.我的相机有另一个问题…拍照后…它会水平显示,而不是全屏显示..>你知道如何解决这个问题吗?你可以使用,并将相应的图像和文本放置在布局中,创建垂直方向的ImageView和TextView,并在TextView中设置文本 这是一个布局技巧,但示例正好显示了您想要的内容
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="center"
android:src="@drawable/golden_gate" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dip"
android:layout_gravity="center_horizontal|bottom"
android:padding="12dip"
android:background="#AA000000"
android:textColor="#ffffffff"
android:text="Golden Gate" />
</FrameLayout>
您可以构建一个新的图像,将图片+过度编写的文本组合成一个新图像,或者将两者显示为屏幕上的图层。这取决于您是否要保存并重新使用此图像和叠加的文本
正如我理解你的问题,这里不是这样(如果我错了,请告诉我,我会更新这个答案)。因此,FrameLayout
是您的朋友:它允许将图形组件显示为套印帧:
<?xml version="1.0" encoding="UTF-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView ...your picture, with the desired attributes />
<TextView ...your text, with the desired attributes />
</FrameLayout>
然后,在布局中使用此类:
<?xml version="1.0" encoding="UTF-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.example.CameraView
android:id="@+id/previewcam"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<TextView ...your text, also with the desired attributes />
</FrameLayout>
我当然有XML。我没有收到任何空异常!我用XML编辑了我的问题。那么下一步怎么办?@george我编辑了我的答案,以考虑到您希望直接查看相机预览(而不是ImageView)是的,但问题是我的ImageView来自相机,而不是可绘制的东西;)
package com.example;
// imports
public class CameraView extends SurfaceView implements SurfaceHolder.Callback {
public CameraView(Context context, AttributeSet attrs) {
super(context, attrs);
initializeSurfaceHolder();
}
public void surfaceCreated(SurfaceHolder holder) {
// call Camera.open(); and Camera.setPreviewDisplay(holder); here
}
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
// Call Camera.setParameters() and Camera.startPreview() here
}
public void surfaceDestroyed(SurfaceHolder holder) {
// Call Camera.stopPreview() and Camera.release() here
}
private void initializeSurfaceHolder() {
// This initializes the SUrfaceHolder of your Camera
final SurfaceHolder holder = getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.example.CameraView
android:id="@+id/previewcam"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<TextView ...your text, also with the desired attributes />
</FrameLayout>