【问题标题】:Merging Multiple TextViews onto a Bitmap - should i use canvas?将多个 TextView 合并到位图上 - 我应该使用画布吗?
【发布时间】:2018-06-08 10:09:44
【问题描述】:

我发现您可以将textviews 添加或合并到bitmap。我有 4 个textviews,我想合并到image 的顶部。

这是我想要实现的屏幕截图(尽管目前这是与图像分开的顶部的文本视图):

图像位于文本视图下方。右上角的图像标题是什么图像不它是

所以我想要做的是,一旦我单击 send 按钮,它就会“打印”或将这些 Textviews 合并到下面的 image bitmap 上,这样我就可以保存或发送图像(使用 textviews 在它)作为我的服务器/设备的一个文件。

到目前为止,我使用了Canvas.draw() 方法,尽管它似乎会相互覆盖,并且我试图保持与屏幕截图相同的布局。

谁能帮忙?

【问题讨论】:

    标签: java android canvas bitmap


    【解决方案1】:

    试试这个...

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
    
        >
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/bottomLayID"
            />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:orientation="vertical"
            >
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:weightSum="2"
                android:padding="8dp"
                >
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Detail work order"
                    android:textStyle="bold"
                    android:gravity="center"
                    android:layout_weight="0.5"
                    />
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Image"
                    android:textStyle="bold"
                    android:gravity="center"
                    android:layout_weight="1.5"
                    />
            </LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:weightSum="2"
                android:padding="8dp"
                >
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textStyle="bold"
                    android:gravity="center"
                    android:layout_weight="0.5"
                    />
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textStyle="bold"
                    android:gravity="center"
                    android:layout_weight="1.5"
                    />
            </LinearLayout>
        </LinearLayout>
        <LinearLayout
            android:id="@+id/bottomLayID"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_alignParentBottom="true"
            >
            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Open Camera"/>
            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Send Image"
                android:background="#99d72e"/>
        </LinearLayout>
    </RelativeLayout>
    

    将背景设置为透明颜色并为 textviews 设置边框。

    您可以通过以下方式将位图设置为图像视图

    ImageView mImg;
    mImg = (ImageView) findViewById(R.id.(your xml img id));
    mImg.setImageBitmap(img);
    

    【讨论】:

      猜你喜欢
      • 2011-10-26
      • 2013-01-22
      • 1970-01-01
      • 2011-03-16
      • 2015-06-15
      • 1970-01-01
      • 2012-12-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多