如何使用EclipseIDEforAndroid为下面的xml代码编写动态代码

如何使用EclipseIDEforAndroid为下面的xml代码编写动态代码,android,eclipse,Android,Eclipse,如何使用eclipse为下面的xml代码编写动态代码 Android的IDE。由于我是初学者,我不知道写动态代码plz帮助我。。 徖 <TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignP

如何使用eclipse为下面的xml代码编写动态代码 Android的IDE。由于我是初学者,我不知道写动态代码plz帮助我。。 徖

    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" >

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >
            <ImageView
               android:id="@+id/imageView1"
               android:layout_width="150dp"
               android:layout_height="200dp"
               android:layout_marginRight="5dp"
               android:scaleType="fitXY"
               android:layout_weight="1"
               android:src="@drawable/image_new1" /> 
            <ImageView
               android:id="@+id/imageView2"
               android:layout_width="150dp"
               android:layout_height="fill_parent"
               android:layout_marginRight="5dp"
               android:scaleType="fitXY"
               android:layout_weight="1"
               android:src="@drawable/image_new2" />
            <ImageView
               android:id="@+id/imageView3"
               android:layout_width="150dp"
               android:layout_height="fill_parent"
               android:layout_marginRight="5dp"
               android:scaleType="fitXY"
               android:layout_weight="1"
               android:src="@drawable/image_new2" />
            <ImageView
               android:id="@+id/imageView4"       
               android:layout_width="150dp"
               android:layout_height="fill_parent"
               android:layout_marginRight="5dp"
               android:scaleType="fitXY"
               adroid:layout_weight="1"
               android:src="@drawable/image_new1" />

        </TableRow>
    </TableLayout>

这是一个动态代码,但使用LinearLayout并在本例中添加您的项目view\u list\u item,您可以实际地执行相同的操作

在你的活动布局中放上这个

<LinearLayout
                android:id="@+id/view_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/splitter"
                android:layout_marginTop="10dp"
                android:orientation="vertical" >

               <ScrollView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" >

                    <!-- as they are added to and removed from the LinearLayout. -->

                    <LinearLayout
                        android:id="@+id/container_view"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:animateLayoutChanges="true"
                        android:divider="?android:dividerHorizontal"
                        android:orientation="vertical"
                        android:showDividers="middle" />
                </ScrollView>
            </LinearLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/main"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <com.csdc.crsmofa.views.TextViewNaskhRegular
        android:id="@+id/item_label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="3dp"
        android:layout_alignParentRight="true"
        android:textAppearance="@style/LoginTextViewAppearnce" />

    <com.csdc.crsmofa.views.TextViewNaskhRegular
        android:id="@+id/item_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_toLeftOf="@+id/item_label"
        android:lines="1" />

</RelativeLayout>
onCreate(...){
ViewGroup containerView = (ViewGroup) view.findViewById(R.id.container_view);
fillView(containerView);


}



private void fillView(final ViewGroup mContainerView) {
                try {


mContainerView.removeAllViews();

ViewGroup newView = (ViewGroup) LayoutInflater
                                    .from(getActivity())
                                    .inflate(R.layout.view_list_item, mContainerView, false);

                            ((TextView) newView.findViewById(R.id.item_label))
                                    .setText("blablabla");
                            ((TextView) newView.findViewById(R.id.item_text))
                                    .setText("blablabla");

mContainerView.addView(newView, 0); 

} catch (Exception ex) {
                String string = ex != null ? ex.getMessage() : "";
                Log.e(TAG, string != null ? string : "");
                ex.printStackTrace();
            }
}