我有两个视图(Textview
和ImageView
)在FrameLayout
,我想保存的图像与文本。为此,我转换为位图视图。
我的xml是:
<FrameLayout
android:id="@+id/framelayout"
android:layout_marginTop="30dip"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<ImageView
android:id="@+id/ImageView01"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<TextView android:id="@+id/text_view"
android:layout_marginTop="30dip"
android:layout_width="wrap_content"
android:maxLines="20"
android:scrollbars="vertical"
android:layout_height="wrap_content"/>
</FrameLayout>
字符串
7条答案
按热度按时间qij5mzcb1#
如何将视图转换为位图
字符串
v1l68za42#
我曾经使用
buildDrawingCache()
方法来获取布局的位图,但是当视图很大时使用I was having trouble with it。现在我使用以下方法:字符串
8cdiaqws3#
你可以使用下面的代码片段得到一个视图的位图
字符串
qoefvg9y4#
为什么不写一个扩展ImageView的类,重写方法onDraw,把你的图片和文本放在那里,这样更容易
4zcjmb1e5#
首先,您需要添加依赖项
字符串
然后将布局转换为位图
型
h5qlskok6#
字符串
在这里我添加了一个post Runnable线程,它确保Bitmap方法只在v.buildDrawingCache(true);. v.buildDrawingCache(true);在某些移动的中需要几毫秒的时间后才执行,这就是它在某些移动的中崩溃的原因。如果您遇到Bitmap对象的空指针异常,请尝试此解决方案。
flmtquvp7#
字符串