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

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

  1. android申请多个运行时权限,Android 6.0(API 23) 运行时权限(二)之权限申请

    Android M 在上一篇中简单介绍了运行时权限,今天就讲讲怎么去申请权限.这个项目中本来用了一个第三方的权限框架,但是不太好用,我就在github上选择了start最多的PermissionsDi ...

  2. Android M 新的运行时权限开发者需要知道的一切

    android M 的名字官方刚发布不久,最终正式版即将来临! android在不断发展,最近的更新 M 非常不同,一些主要的变化例如运行时权限将有颠覆性影响.惊讶的是android社区鲜有谈论这事儿 ...

  3. android方法数据库的权限,Android数据存储,运行时权限

    Android存储目录 Android的底层支持是Linux,不同于Windows,没有分盘的概念,是以文件夹形式呈现,可以理解为一个应用就是一个用户. data目录 手机内部存储目录(手机本身内存) ...

  4. 【Android 逆向】修改运行中的 Android 进程的内存数据 ( 使用 IDA 分析要修改的内存特征 | 根据内存特征搜索修改点 | 修改进程内存 )

    文章目录 一.使用 IDA 分析要修改的内存特征 二.根据内存特征搜索修改点 三.修改进程内存 一.使用 IDA 分析要修改的内存特征 在前的博客 [Android 逆向]逆向修改游戏应用 ( 分析应 ...

  5. 【Android 逆向】修改运行中的 Android 进程的内存数据 ( Android 命令行中获取要调试的应用进程的 PID | 进程注入调试进程内存的 so 库 )

    文章目录 一.Android 命令行中获取要调试的应用进程的 PID 二.进程注入调试进程内存的 so 库 一.Android 命令行中获取要调试的应用进程的 PID 前置博客 [Android 逆向 ...

  6. 【Android 逆向】修改运行中的 Android 进程的内存数据 ( 运行环境搭建 Android 模拟器安装 | 拷贝 Android 平台可执行文件和动态库到 /data/system )

    文章目录 一.运行环境搭建 Android 模拟器安装 二.拷贝 Android 平台可执行文件和动态库到 /data/system 目录下 一.运行环境搭建 Android 模拟器安装 使用低版本的 ...

  7. android linearlayout最大高度,Android中最简单最常用的LinearLayout线性布局

    原标题:Android中最简单最常用的LinearLayout线性布局 良好的布局设计对于UI界面至关重要,在前面也简单介绍过,目前Android中的布局主要有6种,创建的布局文件默认为Relativ ...

  8. Android精通:View与ViewGroup,LinearLayout线性布局,RelativeLayout相对布局,ListView列表组件...

    UI的描述 对于Android应用程序中,所有用户界面元素都是由View和ViewGroup对象构建的.View是绘制在屏幕上能与用户进行交互的一个对象.而对于ViewGroup来说,则是一个用于存放 ...

  9. 精通android布局,Android精通:View与ViewGroup,LinearLayout线性布局,RelativeLayout相对布局,ListView列表组件...

    标题图 UI的描述 对于Android应用程序中,所有用户界面元素都是由View和ViewGroup对象构建的.View是绘制在屏幕上能与用户进行交互的一个对象.而对于ViewGroup来说,则是一个 ...

最新文章

  1. 想学python编程-想学Python编程?你真的适合吗?
  2. Struts2面试问答
  3. 闲鱼:1月13日至1月19日冻结涉欺诈用户1.1万个
  4. opencv Harris角检测
  5. 每日一题[LeetCode 689]三个无重叠子数组的最大和
  6. IE下Ajax缓存(转载)
  7. 基于gdal的格网插值
  8. Cocos2D:塔防游戏制作之旅(九)
  9. matlab安装自行下载的工具箱
  10. 微搭低代码入门教程02
  11. oracle 导入 imp-00008,imp导入文件时报大量的imp-0008错误
  12. Java整合ORC识别验证码
  13. 用计算机研究甲骨文,基于图像识别技术的甲骨文数据系统
  14. html5程序阅读题,20 个重要的 HTML5 面试题及答案
  15. 网页字体弄成微软雅黑html,网页字体替换为微软雅黑
  16. Android OnDeviceAppPrediction 优化
  17. Tensorflow2.x框架-神经网络实现鸢尾花分类
  18. 微信小程序界面设计入门课程-样式wxss中使用css课程-文本-direction 文本方向
  19. 用 200 行 Python 代码掌握基本音乐理论
  20. 爬虫|巨潮资讯网上市公司年报爬取

热门文章

  1. 通过句柄找到广告弹窗进程
  2. 2020——网鼎杯 (青龙组)signal
  3. Fuzz学习笔记(一)—— WinAFL环境搭建与基本使用
  4. 013 Android锁机病毒分析
  5. 1.10 instanceof关键字
  6. Shell中的for循环
  7. MySQL查询的进阶操作--连接查询
  8. MySQL之无限级分类表设计
  9. 最简单实现多线程的方法(Thread)
  10. Nginx压缩输出配置