最近在项目中遇到在代码中滚动当前屏幕的问题

屏幕上的元素 我都是在代码里面动态创建的

我的思路是: 将ScrollView 控件 执行 scrollTo 方法  滚动到适当的位置

至于哪里是合适的位置 我用的是 当前控件的getBottom()  方法

 

 

 

 // 循环 界面 找到要查询的人员
  LinearLayout ll_employee = (LinearLayout) findViewById(R.id.LinearLayout_employee);
  int iCount = ll_employee.getChildCount();
  //
  String tv_NameString = "";
  ScrollView sv = (ScrollView) findViewById(R.id.sv);
  // 首先 将上一次查询的颜色 清除
  for (int i = 0; i < iCount; i++) {
   View myView = (View) ll_employee.getChildAt(i);
   // 人员
   if (myView.getClass() == TextView.class) {
    TextView myTextView = (TextView) myView;

    if (!myTextView.getTag().toString().trim().equals("_bumen")) {
     myTextView.setBackgroundColor(Color.TRANSPARENT);
     //
    }
   }

  }
  //
  for (int i = 0; i < iCount; i++) {
   View myView = (View) ll_employee.getChildAt(i);
   // 人员
   if (myView.getClass() == TextView.class) {
    TextView myTextView = (TextView) myView;

    if (!myTextView.getTag().toString().trim().equals("_bumen")) {
     tv_NameString = myTextView.getText().toString().trim();
     if (tv_NameString.indexOf(employeeName) >= 0) {
      // 已经找到这个人 定位之
      myTextView.setBackgroundColor(Color
        .parseColor("#FF4040"));

      sv.scrollTo(0, myTextView.getBottom() - 100);

      //
     }
    }
   }

  }

相关文章:

  • 2021-08-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-17
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-24
  • 2022-12-23
  • 2022-01-19
  • 2022-12-23
  • 2022-12-23
  • 2022-01-15
  • 2022-12-23
相关资源
相似解决方案