Programatically changing Textview height and width

这一生的挚爱 提交于 2019-12-02 08:07:31

What is your TextView parent layout? Linear, Relative or what? Sample if LinearLayout:

LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
homeButton.setLayoutParams(params);

You must create param base on its parent layout.

Assuming your parent is a LinearLayout

LinearLayout.LayoutParams layoutParam = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
homeButton.setLayoutParams(layoutParam);

You have already given the layout_width = "0dp" and layout_weight="1". So, when other two buttons will hide. This home button will take full width. But View.INVISIBLE won't remove them from taking width. You should use View.GONE so that even if they are not visible, they shouldn't take width.

INVISIBLE:

 This view is invisible, but it still takes up space for layout purposes.

GONE:

 This view is invisible, and it doesn't take any space for layout purposes.

You don't need to set Layout Params again on Home TextView.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!