日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

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

發(fā)布時間:2025/3/20 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android 切换排列,在运行时重新排序android线性布局? 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

我有一個水平線性布局作為我的布局文件中的根元素。線性布局包含兩個相對布局,每個布局都有幾個子元素。我怎樣才能交換這兩個相對布局的位置?在運(yùn)行時重新排序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);

兩個結(jié)果在第二相對布局(RL2)占用的整個寬度。如果需要,我可以發(fā)布我的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

使用層次結(jié)構(gòu)視圖來幫助您確定您的方法出錯的位置。沒有布局文件,任何人都很難幫助你。你的代碼看起來很好。 –

2013-02-10 23:36:06

+0

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

2013-02-10 23:40:13

總結(jié)

以上是生活随笔為你收集整理的android 切换排列,在运行时重新排序android线性布局?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。