我有一个简单的按钮 View ,并将其设置为内容 View 。是否可以通过编程方式将此 View 的大小调整为“wrap_content”?
Button button = new Button(getContext());
button.setText("Some text");
setContentView(button);
最佳答案
使用以下代码设置您的属性:
Button button = new Button(getContext());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
button.setLayoutParams(params);
button.setText("Some text");
setContentView(button);
关于android - 是否可以在没有父 View 的情况下设置 wrap_Content 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35843527/