在代碼中設置RelativeLayout布局中標簽的android:layout_toLeftOf、android:layout_toRightOf等屬性


 

//轉載一個布局文件,要向這個布局匯總動態添加一個button
RelativeLayout relativeLayout(RelativeLayout)getLayoutInflater().inflate(R.layout.main,null); //裝載要動態添加的按鈕布局 Button button = (Button)getLayoutInflater().inflate(R.layout.button,null); //創建一個LayoutParams對象 RelativeLayoutLayoutParamslayoutParams= new RelativeLayout。LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT); layoutParams.addRule(RelativeLayout.RIGHT_OF,R.id.button1); layoutParams.addRule(RelativeLayout.BELOW,R.id.button); button.setLayoutParams(layoutParams); relativeLayout.addView(button);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM