android 切换排列,在运行时重新排序android线性布局?

我有一个水平线性布局作为我的布局文件中的根元素。线性布局包含两个相对布局,每个布局都有几个子元素。我怎样才能交换这两个相对布局的位置?在运行时重新排序android线性布局?

我试图

ViewGroup vg = (ViewGroup)findViewById(R.id.horizontalLayout);

RelativeLayout rl1 = (RelativeLayout)findViewById(R.id.panelLayout);

RelativeLayout rl2 = (RelativeLayout)findViewById(R.id.boardLayout);

vg.removeAllViews();

vg.addView(rl2);

vg.addView(rl1);

我还试图

vg.removeView(rl2);

vg.addView(rl2, 0);

两个结果在第二相对布局(RL2)占用的整个宽度。如果需要,我可以发布我的xml文件,但它很长。此外,两个相对布局的height = match_parent和width = wrap_content。

android:id="@+id/horizontalLayout"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal" >

android:id="@+id/panelLayout"

android:layout_width="wrap_content"

android:layout_height="match_parent" >

android:id="@+id/textView1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentLeft="true"

android:layout_alignParentTop="true"

android:text="@string/next" />

android:id="@+id/previewGridView1"

android:layout_width="100dp"

android:layout_height="150dp"

android:layout_alignParentLeft="true"

android:layout_below="@+id/textView1" />

android:id="@+id/txtScore"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentLeft="true"

android:layout_below="@+id/previewGridView1"

android:text="Score: 0" />

android:id="@+id/button1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentBottom="true"

android:layout_centerHorizontal="true"

android:text="@string/pausestr"

android:onClick="btnPause_Click" />

android:id="@+id/lblPaused"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentLeft="true"

android:layout_below="@+id/txtScore"

android:layout_marginTop="20dp"

android:text="@string/pausedstr"

android:visibility="gone" />

android:id="@+id/button2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_above="@+id/button1"

android:layout_alignRight="@+id/previewGridView1"

android:layout_marginBottom="41dp"

android:text="@string/savestr"

android:onClick="btnSave_Click" />

android:id="@+id/boardLayout"

android:layout_width="wrap_content"

android:layout_height="match_parent" >

android:id="@+id/gridView1"

android:layout_width="match_parent"

android:layout_height="wrap_content" />

android:id="@+id/btnDrop"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentBottom="true"

android:src="@drawable/downarrow"

android:background="@null"

android:onClick="btnDrop_Click" />

android:id="@+id/btnLeft"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentBottom="true"

android:layout_centerHorizontal="true"

android:src="@drawable/leftarrow"

android:background="@null"

android:onClick="btnLeft_Click" />

android:id="@+id/btnRight"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentBottom="true"

android:layout_alignParentRight="true"

android:src="@drawable/rightarrow"

android:background="@null"

android:onClick="btnRight_Click" />

+0

使用层次结构视图来帮助您确定您的方法出错的位置。没有布局文件,任何人都很难帮助你。你的代码看起来很好。 –

2013-02-10 23:36:06

+0

以为我描述了我的布局文件,至少是最重要的部分,但我想你是正确的病后文件。 –

2013-02-10 23:40:13

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值