android implements ScrollView automatic scrolling instance code

  • 2020-05-24 06:06:35
  • OfStack

Sometimes you need to dynamically add data, the screen is full, and the data needs to scroll. Here I want to understand the meaning of the scrollTo(0, off) method.

No more meaning. That's about it.

Here's how to use it:


private void searchResultShow() {
 TextView textView = new TextView(AFSearchActivity.this);   
        textView.setText("Text View ");   
        LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(   
                LinearLayout.LayoutParams.MATCH_PARENT,   
                LinearLayout.LayoutParams.WRAP_CONTENT   
        );   
        textView.setPadding(30, 15, 0, 15);
        textView.setTextSize(30);
        textView.setTextColor(Color.WHITE);
        // increase 1 a TextView To the linear layout 
       layout.addView(textView, p);   

        ImageView imageView = new ImageView(AFSearchActivity.this); 
        imageView.setImageResource(R.drawable.im_dottend_line);

      // increase 1 a ImageView To the linear layout 
        layout.addView(imageView, p);   
        if(sName == null || sName.equals("")){
   textView.setText("-");
  }else{
   textView.setText(sName);
   sName = "";
    mHandler.post(mScrollToBottom);   
  }
 }
 private Runnable mScrollToBottom = new Runnable() 
    {   
        @Override  
        public void run()
        {   
            int off = layout.getMeasuredHeight() - nameScroll.getHeight();   
            if (off > 0) 
            {   
             nameScroll.scrollTo(0, off);   
            }                          
        }   
    };


Related articles: