This is the code.
RelativeLayout layout = new RelativeLayout(this); TextView title = new TextView(this); title.setGravity(Gravity.CENTER); title.setWidth(320); title.setHeight(160) title.setText("hello"); layout.addView(title); layout.setOnTouchListener(this);
On the Screen, when I move the view location from (x:0, y:0) -> to (x: 200, y:300)
And then set the TextView's value
title.setText("aaaaabbbbbbccccccdddddddeeeeeeeddddd");
the string length > textview's width, so multi-line display
Then occurred error is "the TextView's location is back to (x:0, y:0)"
if the TextView is display SingleLine, eg: title.setText("aaa"); the TextView's location is (x:200, y:300)
Is the android textView display multi-line strings, the layout is Redrawn? anyone can help me? I've been worried all night!!!
ps: the same error is also happened when call the TextView.bringToFront();
// In Android,if you changed the view location,must be setting layoutparams;otherwise,when the view reDraw,the view will back to location(0,0)。
// the solution is like this:
RelativeLayout.LayoutParams lpFeedback = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
lpFeedback.leftMargin = v.getLeft();
lpFeedback.topMargin = v.getTop();
lpFeedback.setMargins(v.getLeft(), v.getTop(), 0, 0);
v.setLayoutParams(lpFeedback);