【发布时间】:2021-08-15 01:17:42
【问题描述】:
我有不同的布局。一些由 xml 创建。其他一些通过代码动态。当我在 xml 上时,我可以使用“wrap_content”值设置宽度或高度。如何动态获得相同的结果?这是我的动态 TextView 的 sn-p。我需要删除“final int width = 440;”并获得相同的“wrap_content”值。怎么样?
final int width = 440;
final int height = textViewHeight;
final int top = getNewTop(height);
FrameLayout.LayoutParams layoutParams;
layoutParams = getLayoutParams(width, height, top);
TextView textView;
textView = new TextView(_registerNewMealActivity);
textView.setText(text);
textView.setLayoutParams(layoutParams);
_frameLayout.addView(textView);
【问题讨论】:
-
你在谷歌看到了 wrap_content 吗?
标签: android