{{1}}
这是我的代码,但它不起作用,因为它应该工作。但是,linearLayout的高度和宽度都是从这个代码设置的,也不是边距。我已经花了几个小时和几个小时,但没有找到任何有效的解决方案。
答案 0 :(得分:0)
确保在onCreate函数旁边初始化变量,并在其他函数中使用相同的函数。
public class ExampleActivity extends AppCompatActivity {
LinearLayout mLayout; //Initialize it here
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
buttonClick();
}
public void buttonClick(){
mLayout = (LinearLayout) findViewById(R.id.layout);
mLayout.setOrientation(LinearLayout.VERTICAL);
//Make like this and try!
}
}