两个布局文件:
一个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当中多出Jni的包,怎么回事
- android:build path contains duplicate entry:'src' for project 'XXX'
- 高手进!android GPS问题
- Sqlite插入图片的问题,一直插不进去
- android程序自动更新安装详解.doc
- 为什么在android模拟器上获得的图片的大小和实际图片在photoshop的大小不一样
- Android中获取短信内容后如何传递到另一个Activity
- EditText光标靠右侧
- 【求助】关于回收listview里的图片
- 跪求:第三方嵌入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有木有问题