Что у меня есть - у меня есть frameLayout в xml, который содержит некоторые TextViews. Я добавляю текст в некоторые поля textview в моем коде Java (скажем, MainActivity), тогда как текст в некоторых текстовых представлениях жестко запрограммирован только в файле XML. В моем XML-файле (abc.xml) -
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/screen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:text="Agent name: "
android:textSize="4dp" />
<TextView
android:id="@+id/agentName"
android:layout_marginTop="1dp"
android:textSize="4dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</FrameLayout>
В своей основной деятельности я устанавливаю agentName как - TextView tvAgentName = findViewById(R.id.agentName);
tvAgentName.setText("My first agent");
Что я хочу - создать растровое изображение макетас обоими текстовыми представлениями с текстом as-
Agent name: My first agent
Что я получаю - Растровое изображение с текстом as-
Agent name:
Примечание. Я создаю растровое изображение из макета, используя следующую функцию-
View inflatedFrame = getLayoutInflater().inflate(R.layout.abc, null);
Log.d("INFLAMTE", "onActivityResult: "+inflatedFrame);
frameLayout = inflatedFrame.findViewById(R.id.screen) ;
Log.d("FRAME LAYOUT IS ", "onActivityResult: "+frameLayout);
frameLayout.setDrawingCacheEnabled(true);
frameLayout.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
frameLayout.layout(0, 0, frameLayout.getMeasuredWidth(), frameLayout.getMeasuredHeight());
frameLayout.buildDrawingCache(true);
return frameLayout.getDrawingCache();
}
Thanks in advance.