java - android - 如何在已经膨胀的布局中膨胀 map fragment ?

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

我正在我的 Activity 中创建表布局,在循环中动态添加表行。 我想要实现的目标是在每个动态创建的表格行中添加一个 Google map fragment 。

这是我的表格行布局:

<?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<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 map ,如下图所示(而不是示例图像,有 map ):

http://goo.gl/9erYB7

有办法实现吗? 预先非常感谢您。

最佳答案

我找到了一个在同一个 View 上添加多个 map fragment 的解决方案,按照这个示例,以防有人遇到同样的问题:

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

关于java - android - 如何在已经膨胀的布局中膨胀 map fragment ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26704981/

相关文章:

api - 谷歌地图API获取国家和城市

java - 设置反向安全约束

android - 移除 Action Bar Android

javascript - ASP : Dynamically update a Google Maps engine instance with new coordinates

JavaScript/Angular - 尝试使用本地 JSON 文件设置 Google map 样式时出现问题

android - 如何检测或监控另一个 Android 应用程序中的触摸编辑文本?

java - 无法为GUI更改计算器创建“重置”按钮

java - 如何从java中的jdatechooser知道所选日期是星期几

java - 我无法将整数作为数组的元素

android - kotlin 中缀不适用于一个参数扩展功能