【发布时间】:2017-01-23 15:30:26
【问题描述】:
我对@987654321@ 和setText() 的TextView 有疑问。在setText() 和使用getDrawingCache() 之后,我没有在位图中看到文本。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/mainLinearLayout"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<android.support.v7.widget.Toolbar
android:id="@+id/toolBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparencyGray"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp" >
</android.support.v7.widget.Toolbar>
<TextView
android:id="@+id/idOfTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:shadowColor="@color/black"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="5"
android:layout_gravity="center"
android:textSize="@dimen/textSizeLarge"
/>
</LinearLayout>
代码是:
idOfTextView.setText( "Some special test string" );
// create bitmap screen capture
View v1 = getWindow().getDecorView().getRootView();
//v1.invalidate();
v1.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
Bitmap 具有正确的分辨率,正确的 mainLinearLayout 背景(以编程方式设置,不在本示例中),但我在 Bitmap 中没有看到来自idOfTextView.setText( "Some special test string" ) 的文本:“Some special test string”。
有趣的是:当我将android:text="Test string" 添加到 idOfTextView 时,部分文本(“Some”)显示在位图中。
当我在代码中注释 setText() 并将 android:text="Test string" 添加到 idOfTextView 时,一切正常。
我尝试过:编辑布局、无效、setVisibility、在 Google 上搜索,但我不知道接下来会发生什么。
谢谢。
【问题讨论】:
标签: android android-layout bitmap android-view