1

タッチイベントでディスプレイキーボードビューのコードを記述したカスタムEditTextがあります。スクロールできず、クリックしてもカーソルをタッチ位置に配置できません。動作するタッチ位置にカーソルを配置するためのコードを見つけますedittextがスクロールしなかった場合のみ修正。

コードは次のとおりです。

Layout layout = ((EditText) text).getLayout();
if (layout != null)
{
    int line = layout.getLineForVertical((int) event.getY());
    int offset = layout.getOffsetForHorizontal(line, event.getX());
    ((EditText)text).setSelection(offset);
}

助けてくださいありがとう

4

2 に答える 2

0

1つのレイアウト内に2つのscrollView(Roystonが言ったように)を追加する必要があります(結果は、一部の電話では遅れているように見えます)そのためのコードスニペットを次に示します:最初にxmlで

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/myparentScrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<ScrollView
    android:id="@+id/mychildScrollView"

        <TextView
        / >


</ScrollView>

これをコードビハインドに追加します

 parentScrollView= (ScrollView) findViewById(R.id.myparentScrollview);
parentScrollView.setOnTouchListener(new View.OnTouchListener() {

    public boolean onTouch(View v, MotionEvent event) {
        // TODO Auto-generated method stub
         //Log.v(TAG,"PARENT TOUCH");
         findViewById(R.id.childScrollView).getParent().requestDisallowInterceptTouchEvent(false);
        return false;
        }
    });
childScrollView= (ScrollView) findViewById(R.id.childScrollView);
childScrollView.setOnTouchListener(new View.OnTouchListener() {

    public boolean onTouch(View v, MotionEvent event) {
        // TODO Auto-generated method stub
         //Log.v(TAG,"PARENT TOUCH");
         findViewById(R.id.mychildScrollView).getParent().requestDisallowInterceptTouchEvent(true);
        return false;
    }
});
于 2012-10-03T06:13:54.510 に答える
0

スクロールを有効にするには、 EditText を ScrollView 内に囲む必要があります

于 2012-10-03T05:52:16.387 に答える