我有不同的布局.一些由xml创建.其他一些人通过代码进行动态调整.当我在xml上时,我可以使用“wrap_content”值设置宽度或高度.如何获得相同的结果?这是我的dinamic TextView的片段.我需要删除“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);
解决方法
试试如下:
- FrameLayout.LayoutParams layoutParams;
- layoutParams = getLayoutParams(LayoutParams.WRAP_CONTENT,top);
- TextView textView;
- textView = new TextView(_registerNewMealActivity);
- textView.setText(text);
- textView.setLayoutParams(layoutParams);