ScrollView disable focus move

后端 未结 10 699
野性不改
野性不改 2020-12-14 16:36

I have a simple input form; it\'s a vertical LinearLayout with EditTexts inside a ScrollView.



        
10条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-14 17:18

    I found another easy solution that works for my problem.

    I got a ScrollView with an EditText at the top, and after it, a big list of TextViews, RatingBars and Buttons. The Buttons launch AlertDialogs, and when they pops up, the ScrollView moves to the top, to the EditText that is the one that still has the focus.

    To solve it, I set in the onClick method of the Activity the requestFocusFromTouch() to the view clicked (in this case the Button).

    public void onClick(View v) {
        v.requestFocusFromTouch();
        ...
    }
    

    So now when I click on a Button, the ScrollView moves and put that Button on the center of the screen, that was just what I wanted.

    I hope it help.

提交回复
热议问题