让【改变的TextView】跟随鼠标点击出现的问题
Java代码
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 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>