Thinking View related knowledge

Pondering a question:
will add a View to a ViewGroup, but it does not allocate enough height to the View. When the screen is pulled down to dynamically adjust the height of the View, making it possible to move up and down to show or hide the effect.

The issues involved:

  1. Assigned to the height View 0:
addView(mContainer, new LayoutParams(LayoutParams.MATCH_PARENT, 0));
  1. The View Gravity ViewGroup disposed in the
    (1) Bottom: View ViewGroup always the bottom, as the height is increased gradually up channeling;
    (2) Top: View of ViewGroup always on top and, as the height increases gradually toward descenders;
setGravity(Gravity.BOTTOM);
  1. Setting the View itself Gravity
    (1) Bottom: View the contents of the bottom always in its own region, regardless of their height;
    (2) Top: View the content is always the top most in their area, regardless of their height;
view.setGravity(Gravity.BOTTOM);
  1. getMeasuredHeight和getHeight的区别
    MeasuredHeight—how big a view wants to be within its parent.
    Height—Actual size on screen, at drawing time and after layout.

(1) when to call getMeasuredHeight?
After Custom View, Constructor, call measure () method, you can get getMeasuredHeight ().

measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
mMeasuredHeight = getMeasuredHeight();

? When to Call getHeight ()
using the Handler post a Runnable:

new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                int height = getHeight();
            }
}, 100);
  1. View dynamic adjustment of height
ViewGroup.LayoutParams layoutParams = mView.getLayoutParams();
layoutParams.height = (int) v;
mView.setLayoutParams(layoutParams);

Guess you like

Origin blog.csdn.net/weixin_33933118/article/details/90837035