大佬教程收集整理的这篇文章主要介绍了android – 如何在scrollview中充气另一个xml布局,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
****Main.xml****
这是我的main.xml布局,我希望在scrollview的线性布局中扩展另一个布局.所以请有人建议我如何在滚动视图内膨胀另一个布局.
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:id="@+id/productDetailsLayout" > <LinearLayout android:id="@+id/productDetailsLayout1" android:layout_width="fill_parent" android:layout_height="wrap_content" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> <LinearLayout android:id="@+id/productDetailsLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ScrollView android:id="@+id/scview" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:id="@+id/productDetailsLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" > </LinearLayout> </ScrollView> </LinearLayout> </LinearLayout>
当我膨胀xml然后发生异常.所以请有人帮忙
dynamic_layout.xml
<RelativeLayout xmlns:android="http://scheR_418_11845@as.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/abc" > <ImageView android:id="@+id/icon" android:layout_width="80dp" android:layout_height="80dp" android:paddingLeft="10dp" android:paddingRight="10dp" /> <TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@+id/icon" android:paddingBottom="10dp" android:paddingLeft="5dp" android:text="title" android:textColor="#CC0033" android:textSize="16dp" /> <TextView android:id="@+id/price" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@+id/icon" android:layouT_Below="@+id/title" android:paddingBottom="10dp" android:paddingLeft="5dp" android:text="Price:" android:textColor="#Cd0023" android:textSize="16dp" /> <TextView android:id="@+id/desc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layouT_Below="@+id/price" android:layout_toRightOf="@+id/icon" android:paddingLeft="5dp" android:text="Description" android:textColor="#3399FF" android:textSize="14dp" /> <View android:layout_width="fill_parent" android:layout_height="1dp" android:BACkground="#880808" android:layouT_Below="@+id/desc"/> </RelativeLayout>
请在下面我的代码
LinearLayout mainlayou = (LinearLayout)findViewById(R.id.productDetailsLayout); ScrollView scview=(ScrollView)mainlayou.findViewById(R.id.scview); LinearLayout scviewLayout1 = (LinearLayout)scview.findViewById(R.id.productDetailsLayout1); for(int i=0; i<5; i++){ LayoutInflater inflater = (LayoutInflater)getSystemservice(Context.LAYOUT_INFLATER_serviCE); scviewLayout1.addView(inflater.inflate(R.layout.dynamic_layout,mainlayou,falsE)); }
inflator_layout.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://scheR_418_11845@as.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:id="@+id/llDIsplayForToDoInflater" android:layout_width="fill_parent" android:layout_height="wrap_content" android:BACkground="@color/aliceblue" android:gravity="center" > <TextView android:id="@+id/txtdt" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="20sp" > </TextView> </LinearLayout> </LinearLayout>
Java文件:
LinearLayout llDisplayData,llChangeBG; TextView tvtxt; llDisplayData = (LinearLayout) findViewById(R.id.productDetailsLayout1); LayoutInflater linflater = (LayoutInflater) getSystemservice(Context.LAYOUT_INFLATER_serviCE); View customView; llDisplayData.removeAllViews(); customView = linflater.inflate(R.layout.inflator_layout,null); llChangeBG = (LinearLayout) customView.findViewById(R.id.llDIsplayForToDoInflater); tvtxt = (TextView) customView.findViewById(R.id.txtdt); llDisplayData.addView(customView);
以上是大佬教程为你收集整理的android – 如何在scrollview中充气另一个xml布局全部内容,希望文章能够帮你解决android – 如何在scrollview中充气另一个xml布局所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。