android 从xml中读出一个View再添加到另一个xml中
来源:互联网 发布:microsoft网络客户端 编辑:程序博客网 时间:2024/05/18 00:30
比如现在有两个xml文件main1.xml和main2.xml,需要将main2.xml中的一个view添加到main1.xml中
例如main1.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/relative">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world"
tools:context=".MainActivity" />
</RelativeLayout>
main2.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/linear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<com.symbol.seekbartest.SeekBar
android:id="@+id/verseekbar"
android:layout_width="40dp"
android:layout_height="180dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="72dp"
android:maxHeight="40dip"
android:minHeight="40dip"
android:thumb="@drawable/thumbround1"
android:thumbOffset="0dip"
android:progressDrawable="@layout/seekbar_style"
/>
</LinearLayout>
解决该问题的思路:
(当以main1.xml为主界面时)
在Activity中:
1、首先应该用LayoutInflater获取到main2.xml
View view=LayoutInflater.from(this).inflate(R.layout.main2, null);
2、得到main2中要添加的对象
SeekBar seek = (SeekBar) view.findViewById(R.id.verseekbar);
3、实例化main1.xml和main2.xml中的布局对象
RelativeLayout relative = (RelativeLayout) findViewById(R.id.relative);
LinearLayout linear = (LinearLayout) view.findViewById(R.id.linear);
4、先从main2.xml中的布局文件中将要添加的控件remove掉
linear.removeView(seek);
5、最后将该控件添加到main1.xml布局当中就ok了
relative.addView(seek);
- android 从xml中读出一个View再添加到另一个xml中
- Struts2中从一个action内部跳转到另一个action,怎么配置xml呀?
- Struts2中从一个action内部跳转到另一个action,怎么配置xml
- Android从XML中创建View
- android中如何添加一个监听按钮,点击之后从一个activity跳转到另一个activity
- android实现从一个activity跳转到另一个activity中
- android中创建一个activity类就必须添加到androidmainifest.xml中
- android---xml---include用法(导入另一个XML文件到本布局中)
- android---xml---include用法(导入另一个XML文件到本布局中)
- android---xml---include用法(导入另一个XML文件到本布局中)
- android---xml---include用法(导入另一个XML文件到本布局中)
- android---xml---include用法(导入另一个XML文件到本布局中)
- android---xml---include用法(导入另一个XML文件到本布局中
- android---xml---include用法(导入另一个XML文件到本布局中)
- android---xml---include用法(导入另一个XML文件到本布局中)
- 15-1 工资数据的输入(从一个文件中读出读入另一个文件中)
- 【转载】如何从一个DataTable中添加到属于另一个DataTable的 DataRow
- 使用Java的输入输出流技术将Input.txt的内容逐行读出,每读出一行就顺序为其添加行号(从1开始,逐行递增),并写入到另一个文本文件Output.txt中
- 获取安装程序
- java通过IP地址获取物理位置
- DIV CSS完美兼容IE6/IE7/FF的通用方法
- Android 4.0系统打电话和接电话系统流程时序图详解
- URL 学习(一些零碎的笔记)
- android 从xml中读出一个View再添加到另一个xml中
- 解决wordpress的访问权限问题
- SQL Server 2008 定时执行sql语句作业的制定
- 十大不靠谱的话
- Android 动态改变控件大小
- 字符设备和块设备的区别
- 第一次的编程
- Java SE 环境安装和配置
- /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory