It seems
tv.setTypeface(Typeface.MONOSPACE);
did the trick. It is a font that makes all characters with the same width.
سؤال
I have a client socket which sends some lines (ANSI encoding) which forms a shape. The problem is that in the log cat, when i print out the lines, they form a complete shape, but in my Layout, textviews are not forming the shape even when they have the same length. I can see that the problem lies with the byte size of the space character. But since i can see it on the log cat, there must be a way to set the textviews to form a complete shape. I tried to replace all the space characters with and set the texts as an html form but still no luck. Is there a way that I'm missing?
class ClientThread implements Runnable {
private BufferedReader input;
@Override
public void run() {
// TODO Auto-generated method stub
try {
InetAddress servAddress = InetAddress.getByName(SERVER_IP);
socked = new Socket(servAddress, SERVERPORT);
input = new BufferedReader(new InputStreamReader(socked.getInputStream(), "windows-1252"));
while(!Thread.currentThread().isInterrupted()) {
String read = input.readLine();
updateConversationHandler.post(new updateUIThread(read));
}
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
class updateUIThread implements Runnable {
String msg;
public updateUIThread (String str) {
this.msg = str;
}
@Override
public void run() {
// TODO Auto-generated method stub
TextView tv = new TextView(cont);
tv.setTextColor(Color.WHITE);
// tv.setText(makeTextWithColors(msg));
// tv.setText(msg + "count: " + msg.length());
tv.setText(msg);
screen.addView(tv);
scroller.post(new Runnable() {
public void run() {
scroller.smoothScrollTo(0, screen.getBottom());
}
});
}
}
لا يوجد حل صحيح
نصائح أخرى
It seems
tv.setTypeface(Typeface.MONOSPACE);
did the trick. It is a font that makes all characters with the same width.
TextView tb;
tb.setTextSize(20);
tb = Text View it will get floating point value of size you can put there integral type value