Java代码
- Java code
public class MoveViews extends Activity { public static final String[] value = { "Hello", "Hello Kitty", "中国,我爱你,我的祖国!!!", "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" }; int length = value.length; TextView tv; int i = 0; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); tv = (TextView) this.findViewById(R.id.showtext); } public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { tv.layout((int) event.getX(), (int) event.getY(), (int) event .getX() + tv.getWidth(), (int) event.getY() + tv.getHeight()); tv.setVisibility(View.VISIBLE); tv.setText(value[i]); i++; if (i >= value.length) { i = 0; } } return false; }}
XML布局
- XML code
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/layout" ><EditText android:id="@+id/showtext" android:layout_width="100dp" android:layout_height="wrap_content" android:visibility="invisible" /></RelativeLayout>
那位大侠帮我解释下,为什么当我的EditText里面的内容高度改变的时候,我的EditText就回到原点了呢 ??求解啊
救命啊!
------解决方案--------------------
高度变了,会重新计算位置,如果没有设置布局参数,就会从原点开始啊。