两个布局文件:
一个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" > <TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<LinearLayout
android:id="@+id/add"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"></LinearLayout></LinearLayout>
一个test.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ListView
android:id="@+id/caiList"
android:layout_width="400dp"
android:layout_height="wrap_content"></ListView>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/caiImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"/>
<TextView
android:text="简洁"
android:id="@+id/jianjie"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout> 一个java文件:
public class TestAddViewActivity extends Activity {
private LinearLayout page;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
page=(LinearLayout) this.findViewById(R.id.add);
View view1=LayoutInflater.from(getApplicationContext()).inflate(R.layout.test, null);
page.addView(view1);
}
}
想法就是在一个布局文件中引用另一个布局文件,设置布局,但是貌似addView没起作用,什么都没显示
一个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" > <TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<LinearLayout
android:id="@+id/add"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"></LinearLayout></LinearLayout>
一个test.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ListView
android:id="@+id/caiList"
android:layout_width="400dp"
android:layout_height="wrap_content"></ListView>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/caiImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"/>
<TextView
android:text="简洁"
android:id="@+id/jianjie"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout> 一个java文件:
public class TestAddViewActivity extends Activity {
private LinearLayout page;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
page=(LinearLayout) this.findViewById(R.id.add);
View view1=LayoutInflater.from(getApplicationContext()).inflate(R.layout.test, null);
page.addView(view1);
}
}
想法就是在一个布局文件中引用另一个布局文件,设置布局,但是貌似addView没起作用,什么都没显示
解决方案 »
- android源码在linux下mm编译,如何导入第三方jar包?
- Android-x86使用心得
- 请问如何屏蔽Android音量加减时弹出的对话框?
- sipdroid缺少文件问题
- 闹钟问题
- ophone上的应用开发到底和android的开发有啥区别?
- 滑动工具条如何实现
- 求助!!!!!!!!android15应该用什么版本的sdk和adt,谁有对应版本的内有邮箱
- 异常消息处理
- 数据库操作的异常Cannot perform this operation because the connection pool has been close
- 跪求:第三方嵌入Pad QQ尾巴 教程
- android使用webview在3G网络下的问题
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">明显两个不能同时为fp,第二个改成wrap_content就ok了。
page.addView(view1);view1加在page上,检查下看page有木有问题