我有一个按钮。在onClick()中它将同时显示TextView和ImageView,结果相同。但是我遇到问题,图像没有完全加载。有谁能告诉我为什么会这样?提前致谢!
Button onClick的代码
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
switch(count){
case 0 :
df = Typeface.createFromAsset(getAssets(),
"fonts/IDAutomationHC39M_FREE.otf");
ConvertToBitmap();
break;
case 1:
df = Typeface.createFromAsset(getAssets(),
"fonts/code128.ttf");
ConvertToBitmap();
break;
case 2:
df = Typeface.createFromAsset(getAssets(),
"fonts/Molot.otf");
ConvertToBitmap();
break;
case 3:
df = Typeface.createFromAsset(getAssets(),
"fonts/Days.otf");
ConvertToBitmap();
break;
case 4:
df = Typeface.createFromAsset(getAssets(),
"fonts/Paranoid.otf");
ConvertToBitmap();
break;
}
}
});
TextView和ImageView的代码
public void ConvertToBitmap(){
if (et.getText().toString().equals("")) {
//Clear textView
tv.setText("");
et.setText("");
tv.buildDrawingCache();
iv.setImageBitmap(tv.getDrawingCache());
}
else {
TextView tv1 = (TextView) findViewById(R.id.textView1);
tv1.setTypeface(df);
String editTextValue = et.getText().toString();
tv.setText(editTextValue);
tv.buildDrawingCache();
bmap = tv.getDrawingCache();
iv.setImageBitmap(bmap);
}
}
EDITED! Layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gameScreen"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" xmlns:app="http://schemas.android.com/tools">
<com.example.textdrawn3.Text
android:id="@+id/textDrawn"
android:layout_width="match_parent"
android:layout_height="46dp"
android:layout_weight="3.11" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.75"
android:text="TextView" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.75"
android:orientation="horizontal"
android:src="@drawable/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#0000cd"
android:orientation="horizontal" >
<Button
android:id="@+id/btnText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text"
android:textColor="#ffffff"
android:textSize="25sp"
android:typeface="serif" />
<Button
android:id="@+id/btnStop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Stop"
android:textColor="#ffffff"
android:textSize="25sp"
android:typeface="serif" />
<Button
android:id="@+id/btnOK"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OK"
android:textColor="#ffffff"
android:textSize="25sp"
android:typeface="serif" />
<Button
android:id="@+id/btnImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Image"
android:textColor="#ffffff"
android:textSize="25sp"
android:typeface="serif" />
<Spinner
android:id="@+id/fonts_spinner"
android:layout_width="135dp"
android:layout_height="wrap_content"
android:textAlignment="center"
app:context=".TextDrawn3" />
<EditText
android:id="@+id/editText1"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:ems="10"
android:freezesText="false"
android:hint="text"
android:maxLength="10"
android:maxLines="1"
android:textAlignment="center"
android:textColor="#e6e6fa"
android:textSize="25sp"
android:typeface="serif"
android:visibility="visible" >
<requestFocus />
</EditText>
</LinearLayout>