android - 如何在已经膨胀的布局中膨胀地图片段?

时间:2014-11-02 22:05:00

标签: java android google-maps android-layout android-fragments

我在我的活动中创建表格布局,在循环中动态添加表格行。 我想要实现的是在每个动态创建的表行中添加一个Google地图片段。

这是我的表格行布局:

<?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>

这是我动态创建表行的循环:

  

final 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; i&lt; 3; i ++){

  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();                         
      }
  });     
     

}

我想在每个表行中显示一个Google地图,如下图所示(而不是示例图片,包含地图):

http://goo.gl/9erYB7

有没有办法实现这个? 非常感谢你提前。

1 个答案:

答案 0 :(得分:3)

我找到了一个解决方案,可以在同一个视图中添加多个地图片段,如果有人遇到同样的问题:

http://saadroid.blogspot.gr/2013/06/multiple-maps-in-same-view.html