我想在屏幕上绘制文字。 但是在secreen.help me plz上没有任何显示。 我的代码在这里。
Main.java类
public class MainActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
int w = 30, h = 30;
Bitmap.Config conf = Bitmap.Config.ARGB_8888;
Bitmap bmp = Bitmap.createBitmap(w, h, conf);
Canvas canvas = new Canvas(bmp);
Paint paint = new Paint();
Typeface face=Typeface.createFromAsset(getAssets(),"RECOGNITION.ttf");
paint.setColor(Color.BLACK);
paint.setTypeface(face) ;
paint.setTextSize(20);
canvas.drawText("Some Text", 30, 30, paint);
}
但屏幕上没有显示。
我的xml在这里.. mystyle.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
</RelativeLayout>
答案 0 :(得分:0)
试试这个 -Main.java -
public class MAIN extends Activity {
CustomDrawableView mCustomDrawableView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mCustomDrawableView = new CustomDrawableView(this);
setContentView(mCustomDrawableView);
}
}
- CustomDrawableView.java -
public class CustomDrawableView extends View {
//private ShapeDrawable mDrawable;
int x=0;
int y=0;
public CustomDrawableView(Context context) {
super(context);
}
protected void onDraw(Canvas canvas) {
Paint mPaint = new Paint();
mPaint.setColor(0xffff0000);
canvas.drawCircle(x, y, 5, mPaint);
}
}