安卓相对布局动态添加控件,控件布局属性无效 布局安卓控件xmlrelativelayout 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你要获取到xml中RelativeLayout的id,在Relativelayout的基础上addView代码:protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_test); // 装载要填充的布局文件 RelativeLayout rl = (RelativeLayout)findViewById(R.id.rl); Button btn=new Button(this); btn.setText("haha"); // 创建新的LayoutParam对象 RelativeLayout.LayoutParams rlp=new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); rlp.addRule(RelativeLayout.BELOW,R.id.btn1); rlp.addRule(RelativeLayout.RIGHT_OF,R.id.btn1); // 这里的相对位置设置不起作用!为何? btn.setLayoutParams(rlp); if(rl != null) rl.addView(btn); //addContentView(btn, rlp); }xml布局<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/rl" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="1" android:id="@+id/btn1" ></Button> </RelativeLayout> // 装载要填充的布局文件RelativeLayout rl=(RelativeLayout)getLayoutInflater().inflate(R.layout.activity_test, null);为什么这里没起作用啊? 求解答安卓蓝牙通信方面的问题 有关android中使用第三方jar 请问这个是什么意思 请问我写的这个类中,为什么第一个动画不能切换图片?(AnimationDrawable) 这个warn死活没找到原因 MediaPlayer同步播放问题 很低级的问题问一下,一个listview中如何添加不用布局的item? android frame动画在activity中自动播放问题 基站定位得到的cid数值不对 Android 4.2 的屏幕锁的源码在哪儿? 熟悉的给指点一下 apk能实现动态编译吗 网站手机版问题
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_test);
// 装载要填充的布局文件
RelativeLayout rl = (RelativeLayout)findViewById(R.id.rl);
Button btn=new Button(this);
btn.setText("haha");
// 创建新的LayoutParam对象
RelativeLayout.LayoutParams rlp=new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
rlp.addRule(RelativeLayout.BELOW,R.id.btn1);
rlp.addRule(RelativeLayout.RIGHT_OF,R.id.btn1);
// 这里的相对位置设置不起作用!为何?
btn.setLayoutParams(rlp);
if(rl != null)
rl.addView(btn);
//addContentView(btn, rlp); }xml布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/rl"
>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:id="@+id/btn1"
></Button>
</RelativeLayout>
RelativeLayout rl=(RelativeLayout)getLayoutInflater().inflate(R.layout.activity_test, null);为什么这里没起作用啊?