例如,如果你想要将LayoutParams某些视图更改WRAP_CONTENT为两者width和heightprogrammaticaly,它将看起来像这样:
final ViewGroup.LayoutParams lp = yourView.getLayoutParams();
lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
lp.width = ViewGroup.LayoutParams.WRAP_CONTENT;
Run Code Online (Sandbox Code Playgroud)
因为我不知道getLayoutParams返回params的引用,所以这段代码就足够了,但我经常在例子中看到等等,在这一行之后,一个如下:
yourView.setLayoutParams(lp);
Run Code Online (Sandbox Code Playgroud)
我想知道这条线的重点是什么.这只是为了更好的代码可读性,还是有些情况下没有它就无法工作?