
Ayuda Java con eclipse.Quiero dibujar texto obteniendo mi texto y mi posicion por parametros
Publicado por jhon charles (1 intervención) el 31/10/2013 17:20:03
" esta es mi programacion a mostrar en una actividad para dibujar mi texto obteniendo mis parametros de otra actividad "
mi problema es que en la compilacion no me sale un error pero ya comprobe k si me esta reciviendo los parametros ahor mi problema es k cuando seleciono ir ala ventana a mostrar mi texto dibujado me sale error se ha detenido la aplicacion :( . mi codigo es este a mostrar en mi actividad de dibujar texto.
mi problema es que en la compilacion no me sale un error pero ya comprobe k si me esta reciviendo los parametros ahor mi problema es k cuando seleciono ir ala ventana a mostrar mi texto dibujado me sale error se ha detenido la aplicacion :( . mi codigo es este a mostrar en mi actividad de dibujar texto.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.view.View;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Typeface;
public class Vfuepredeterminada extends Activity {
//declarando variable para obtener el parametro
String textoreci,pos_x,pos_y;
//Declarando variable para los controles textview
TextView tvtextore, tvposxre, tvposyre;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_vfuepredeterminada);
//obteniendo el parametro enviado
Bundle bundle=getIntent().getExtras();
textoreci = bundle.getString("textodibujar");
pos_x = bundle.getString("ubicacion_x");
pos_y = bundle.getString("ubicacion_y");
//haciendo referencia a los textview para mostrar los datos
tvtextore=(TextView)findViewById(R.id.tvtexto);
tvposxre=(TextView)findViewById(R.id.tvposx);
tvposyre=(TextView)findViewById(R.id.tvposy);
//mostrando el parametro enviado
tvtextore.setText(textoreci);
tvposxre.setText(pos_x);
tvposyre.setText(pos_y);
//para el lienzo de dibujo
LinearLayout linearLayout = (LinearLayout)findViewById(R.id.LinearLayout1);
Lienzo fondo=new Lienzo(this);
linearLayout.addView(fondo);
}
@SuppressLint("DrawAllocation")
class Lienzo extends View {
public Lienzo(Context context) {
super(context);
}
protected void onDraw(Canvas canvas) {
canvas.drawRGB(50,100,255);
Paint pincel1=new Paint();
pincel1.setARGB(255,255,255,0);
pincel1.setTypeface(Typeface.SANS_SERIF);
String testore=tvtextore.getText().toString();
String postex=tvposxre.getText().toString();
String postey=tvposyre.getText().toString();
int posix=Integer.parseInt(postex);
int posiy=Integer.parseInt(postey);
dibujarTexto(canvas, testore, 40, posix, posiy, pincel1);
}
private void dibujarTexto(Canvas canvas, String texto, int tam, int posx, int posy, Paint pincel) {
Typeface miFuente=Typeface.create(Typeface.SERIF, Typeface.ITALIC);
pincel.setTextSize(tam);
pincel.setTypeface(miFuente);
canvas.drawText(texto, posx, posy, pincel);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.vfuepredeterminada, menu);
return true;
}
}
Valora esta pregunta


0