我在我的一個活動中創建一個Table Layout,在一個循環中動態添加表格行。 我想要實現的是在每個動態創建的表格行中添加Google地圖片段。android - 如何在已經膨脹的佈局中膨脹地圖片段?
這是我的錶行佈局:
<?xml version="1.0" encoding="utf-8">
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rl_rowitem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="15dp">
<RelativeLayout
android:id="@+id/inflated_row_relative"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_poi_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/orange"
android:textColor="#ffffff"
android:text="Name"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="@+id/img_snapshot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/tv_poi_name"
android:adjustViewBounds="true"
android:src="@drawable/map_snapshot" />
<TextView
android:id="@+id/tv_poi_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Address"
android:textColor="#fe8301"
android:layout_below="@+id/img_snapshot"
android:textAppearance="?android:attr/textAppearanceMedium" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/distance_layout"
android:layout_below="@+id/tv_poi_address" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@drawable/distance_icon" />
<TextView
android:id="@+id/tv_poi_distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/imageView1"
android:text="Distance"
android:paddingLeft="10dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
</RelativeLayout>
</TableRow>
這是我動態創建的錶行的循環:
最終TableLayout tblAddLayout =(TableLayout)findViewById(R.id .tl_menu_pois); TableRow inflateRow =(TableRow)View.inflate(Menu_pois.this,R.layout.menu_pois_rowitem,null);
的for(int i = 0;我< 3;我++){View inflate = (TableRow) View.inflate(Menu_pois.this, R.layout.menu_pois_rowitem, >tl_menu_pois); RelativeLayout inflated_row_relative = (RelativeLayout) >inflate.findViewById(R.id.inflated_row_relative); inflated_row_relative.setTag(i); TextView poi_name = (TextView) inflate.findViewById(R.id.tv_poi_name); TextView poi_address = (TextView) inflate.findViewById(R.id.tv_poi_address); poi_name.setText("Name"); poi_address.setText("Address"); //set tag for each TableRow inflate.setTag(i); //add TableRows to TableLayout tblAddLayout.addView(inflate); //set click listener for all TableRows inflated_row_relative.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Object tag = v.getTag(); String string_tag = tag.toString(); } });
}
我要顯示的每個表列等圖像波紋管(而不是樣品中的谷歌地圖圖像,具有地圖):
是否有實現這個的方法嗎? 非常感謝您提前。