配售之外的另一个相对布局外的相对布局编程 [英] Placing one relative layout beside another relative layout programatically
本文介绍了配售之外的另一个相对布局外的相对布局编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有当前显示以下任一其他两个相对布局。我想,以便显示给所述第一相对布局的右边的第二布局编程
I have two relative layouts that are currently displayed one below the other. I want the second layout to be displayed to right of the first relative layout programatically.
以下是code I使用。
following is the code i used.
main.xml中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="620dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/lay1" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello1" />
</RelativeLayout>
<RelativeLayout
android:layout_width="620dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/lay2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello2" />
</RelativeLayout>
</LinearLayout>
myAct.java
myAct.java
public class myAct extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LinearLayout layoutContainer = new LinearLayout(this);
layoutContainer.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
// Arguments here: width, height, weight
LinearLayout.LayoutParams childLp = new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1);
RelativeLayout layoutLeft = new RelativeLayout(this);
layoutContainer.addView(layoutLeft, childLp);
RelativeLayout layoutRight = new RelativeLayout(this);
layoutContainer.addView(layoutRight, childLp);
}
}
在此先感谢
推荐答案
您的线性布局方向改为水平。我还设置一个重量总和的线性布置为2,并给每个相对布局1:1的重量,以确保均匀地分割
Change your linear layout orientation to horizontal. I would also set a weight sum of the linear layout to 2, and give each relative layout a weight of 1 to make sure evenly split.
这篇关于配售之外的另一个相对布局外的相对布局编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文