在Android的聊天泡泡可调嵌入的ImageView [英] insert imageview in android chat bubble adjustable

查看:241
本文介绍了在Android的聊天泡泡可调嵌入的ImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做到这一点对我的机器人聊天

I would like to do this on my android chat

但我不能让我的照片适合我的泡沫。 -I有一个的LinearLayout,并且他的背景是一个气泡9patch -within这一点,我有一个ImageView的,在这里插入图像 但不知道如何使这个适应的背景就像我们在屏幕上看到。

but I can not get my picture fit my bubble. -I have a LinearLayout, and his background is a bubble 9patch -within this, I have a imageview, insert the image here but not how to make this fit the background like we see on screen.

这是我的形象是如何

可以给我的我怎么能做到这一点的想法?

感谢。

更新:28/04/2013

这是我的布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rtlImganen"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginRight="25dp"
    android:gravity="center_vertical" >

    <LinearLayout
        android:id="@+id/lnyGenImagenMio"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:background="@drawable/bocadilloazulmio"
        android:gravity="right"
        android:orientation="vertical" >

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <ImageView
                android:id="@+id/imgImagenMio"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true"
                android:adjustViewBounds="true"
                android:maxHeight="@dimen/maximagen"
                android:maxWidth="@dimen/maximagen"
                android:scaleType="centerCrop" />

            <ImageView
                android:id="@+id/imgPlayMio"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true"
                android:src="@drawable/play" />
        </RelativeLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp" >

            <ImageView
                android:id="@+id/imgImagenEnvioRecibidoMio"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:src="@drawable/enviadorecibido" />

            <TextView
                android:id="@+id/txtFechaImagenVideoMio"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:textColor="#0000FF"
                android:textSize="8sp" />

        </LinearLayout>

    </LinearLayout>

</RelativeLayout>

但我还是haven't解决方案

yet I still haven´t the solution

推荐答案

这只能通过自定义视图完成。我有同样的问题。寻找定制的ImageView和路径裁剪位图。我写这个片段剪辑讲话泡沫塑造出一个给定的位图:

this can only be done with a custom view. I had the same problem. Look for Custom ImageView and Paths and clipping Bitmaps. I wrote this snippet to clip a speech bubble shape out of a given bitmap:

  public static Bitmap clipit(Bitmap bitmapimg,int direct) {

    //1 = direction right
    //0 = direction left

      Bitmap output = Bitmap.createBitmap(bitmapimg.getWidth(),
                bitmapimg.getHeight(), Config.ARGB_8888);
        Canvas canvas = new Canvas(output);

        final int color = 0xff424242;
        final Paint paint = new Paint();
        final Rect rect = new Rect(0, 0, bitmapimg.getWidth(),
                bitmapimg.getHeight());

        paint.setAntiAlias(true);
        canvas.drawARGB(0, 0, 0, 0);
        paint.setColor(color);

        if(direct == 0) {
        canvas.drawRect(0, 0, bitmapimg.getWidth()-15, bitmapimg.getHeight(), paint);
        Path path = new Path();
        path.moveTo(bitmapimg.getWidth()-15, 10);
        path.lineTo(bitmapimg.getWidth(), 20);
        path.lineTo(bitmapimg.getWidth()-15, 30);
        path.lineTo(bitmapimg.getWidth()-15, 10);
        canvas.drawPath(path,paint);
        }
        if(direct == 1) {
            canvas.drawRect(15, 0, bitmapimg.getWidth(), bitmapimg.getHeight(), paint);             
            Path path = new Path();
            path.moveTo(15, 10);
            path.lineTo(0, 20);
            path.lineTo(15, 30);
            path.lineTo(15, 10);
            canvas.drawPath(path,paint);    
        }


        paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
        canvas.drawBitmap(bitmapimg, rect, rect, paint);
        return output;

  }

这是否解决问题了吗?

does this solve your problem?

这篇关于在Android的聊天泡泡可调嵌入的ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆