在android开发中,常常会动态地生成些控件,并调调整其布局。那么,如何动态调整空间的布局,请参阅下面的关键代码:
mRlMain = (RelativeLayout) findViewById(R.id.rlMain); LayoutParams layoutParams = new LayoutParams( android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT); mBtnView = LayoutInflater.from(mContext).inflate(R.layout.photoright, null); layoutParams.addRule(RelativeLayout.CENTER_VERTICAL,RelativeLayout.TRUE); layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT,RelativeLayout.TRUE); mRlMain.addView(mBtnView, layoutParams);主要用到的类有:android.widget.RelativeLayout.LayoutParams,android.view.ViewGroup.LayoutParams及android.widget.RelativeLayout
上面的主要是用相对布局设置,其他布局方式类似。
本文详细介绍了在Android开发中动态生成控件并调整布局的方法,重点讲解了使用RelativeLayout.LayoutParams和ViewGroup.LayoutParams进行布局调整的技巧,适用于Android应用开发者。
1014

被折叠的 条评论
为什么被折叠?



