所以我想做的是能够点击我的TextView。我的 ScrollView 中有一个 TextView,我正在尝试制作它,所以当我点击屏幕时会发生一个事件。目前,当我点击我的 TextView 时,该事件将会发生。但是,问题就出在这里:当我只有一行文字时,我必须点击那一行文字才能检测到onTouch。我想扩展我的 TextView 以覆盖屏幕上的空白区域(我的屏幕底部有两个按钮)。使用真正的手势控制的问题在于,当我点击屏幕上的按钮时,它也会检测到,这使得它对单击毫无用处。我一直试图弄清楚这一点,但由于某种原因它不起作用。这是我的代码。
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()){
case R.id.close:
finish();
break;
case R.id.flashcard:
if(tv.getText().equals(myCursor.getString(iFront))) {
tv.setText(myCursor.getString(iBack));
break;
}
tv.setText(myCursor.getString(iFront));
break;
case R.id.add_new:
Intent list = new Intent("com.example.flashcards.ADD_FLASHCARD");
startActivity(list);
break;
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:id="@+id/scrollable"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight=".1"
android:gravity="center">
<TextView
android:id="@+id/flashcard"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:scrollbars="vertical"
android:textSize="20dp" />
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/add_new"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.55"
android:text="Add New" />
<Button
android:id="@+id/close"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.55"
android:text="close" />
</LinearLayout>
</LinearLayout>