android 怎么在布局里面获取控件
1个回答
展开全部
layout为布局,布局里面可以放任何空间,获取空间可以用findViewById方法获取
android 获取某个布局控件 添加到另一个布局中
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LinearLayout relativeLayout = (LinearLayout) findViewById(R.id.layout456);
ImageView imgApple2 = new ImageView(this);
imgApple2.setImageResource(R.drawable.ic_launcher);
relativeLayout.addView(imgApple2);
LayoutInflater factorys = LayoutInflater.from(MainActivity.this);
final View textEntryView = factorys.inflate(R.layout.layout1, null);
// LinearLayout linearLayout = (LinearLayout) textEntryView
// .findViewById(R.id.layout1);
// relativeLayout.addView(linearLayout);
EditText editText1 = (EditText) textEntryView
.findViewById(R.id.editText1);
relativeLayout.addView(editText1);
android 获取某个布局控件 添加到另一个布局中
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LinearLayout relativeLayout = (LinearLayout) findViewById(R.id.layout456);
ImageView imgApple2 = new ImageView(this);
imgApple2.setImageResource(R.drawable.ic_launcher);
relativeLayout.addView(imgApple2);
LayoutInflater factorys = LayoutInflater.from(MainActivity.this);
final View textEntryView = factorys.inflate(R.layout.layout1, null);
// LinearLayout linearLayout = (LinearLayout) textEntryView
// .findViewById(R.id.layout1);
// relativeLayout.addView(linearLayout);
EditText editText1 = (EditText) textEntryView
.findViewById(R.id.editText1);
relativeLayout.addView(editText1);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询