【问题标题】:Android - how to ensure that checked radiobutton in ScrollView will be visible on screen?Android - 如何确保 ScrollView 中选中的单选按钮在屏幕上可见?
【发布时间】:2011-12-19 21:16:51
【问题描述】:

我在 DialogPreference 的 ScrollView 中有带有 19 个 RadioButtons 的 RadioGroup。对话框中仅在前 7 个 RadioButtons 附近可见。一切正常,只有一个问题。绑定对话框后,如何确保选中的 RadioButton 在屏幕上始终可见?如何以编程方式在 ScrollView 中滚动以显示隐藏的选中 RadioButton?

感谢您的帮助或建议。

【问题讨论】:

    标签: android android-layout radio-button


    【解决方案1】:

    这对我有用。

    final Scrollview scrollview = findViewById(R.id.myScrollView);
    final RadioGroup rg = findViewById(R.id.myRadioGroup);
    int position = //checked position
    
        scrollView.post(new Runnable() {
            @Override
            public void run() {
                scrollView.scrollTo(0, rg.getChildAt(position).getTop());
            }
        });
    

    【讨论】:

      【解决方案2】:

      你应该可以做这样的事情

      int top = checkedRadioButton.getTop();
      scrollView.scrollTo(0,top);
      

      【讨论】:

      • 完美,工作正常。这就是我一直在寻找的。非常感谢。
      猜你喜欢
      • 2019-10-18
      • 2020-11-08
      • 2011-04-28
      • 2018-10-03
      • 2012-09-24
      • 2012-03-08
      • 2017-09-08
      • 1970-01-01
      • 2016-05-10
      相关资源
      最近更新 更多