Android 2.x中的infowindow背景发生错误

X_H

这是我在所有信息窗口中都过大的问题,我想设置为180dp高和300dp宽,或者设置为warp_content:

我意识到问题仅出现在2.2和Android 2.3版本中,在Android 4.1上没有问题,并且我不尝试在3.x版本上使用

知道如何解决吗?

我读了另一篇文章,说更改了getInfoContentfor getInfoWindow,但是我已经有这种方式了。

在此处输入图片说明

InfoWindow.xml:

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#243439"
android:orientation="horizontal" >

<ImageView 
android:id="@+id/imagen"
android:layout_width="114dp"
android:layout_weight="0.5"
android:layout_height="174dp"
android:contentDescription="@string/app_name"/>

<LinearLayout
android:layout_width="174dp"
android:layout_height="174dp"
android:orientation="vertical" >

<TextView
android:id="@+id/titulo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:textColor="#FFFFFF" 
android:gravity="center_horizontal|center"
android:textSize="17sp"
android:textStyle="bold" />

<TextView
android:id="@+id/direccion"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:textColor="#FFFFFF" 
android:gravity="center_horizontal|center"
android:textSize="12sp" />

<TextView
android:id="@+id/vermas"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:textColor="#FFFFFF" 
android:gravity="bottom|center_horizontal"
android:text="@string/vermas"
android:textSize="12sp" />

</LinearLayout>
</LinearLayout>

fragment.java:

googlemap.setInfoWindowAdapter(new InfoWindowAdapter() {

  @Override
  public View getInfoWindow(Marker marker) {

  View v = getLayoutInflater(null).inflate(R.layout.infowindow, null);

  TextView titulo = (TextView) v.findViewById(R.id.titulo);
  TextView direccion = (TextView) v.findViewById(R.id.direccion);
  ImageView imagen = ((ImageView)v.findViewById(R.id.imagen));

  titulo.setText(marker.getTitle());
  direccion.setText(marker.getSnippet());

  if(hash.get(marker) != null)
  imagen.setImageDrawable(getResources().getDrawable(hash.get(marker)));

  return v;

  }
  //..
  @Override
  public View getInfoContents(Marker marker) {
 // TODO Auto-generated method stub
return null;
  }
  });
  }
X_H

看,我发布了我拥有的最终代码,希望对您有所帮助

Infowindow.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="294dp"
android:layout_height="180dp"
android:background="@drawable/rectangle_infowindow"
android:gravity="center"
android:orientation="horizontal" >

<ImageView 
    android:id="@+id/imagen"
    android:layout_width="114dp"
    android:layout_height="174dp"
    android:contentDescription="@string/app_name"/>

<LinearLayout
    android:layout_width="174dp"
    android:layout_height="174dp"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/titulo"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:textColor="#FFFFFF" 
        android:gravity="center_horizontal|center"
        android:textSize="17sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/direccion"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="14dp"
        android:textColor="#FFFFFF" 
        android:gravity="center_horizontal|center"
        android:textSize="12sp" />

    <TextView
        android:id="@+id/vermas"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:textColor="#FFFFFF" 
        android:gravity="bottom|center_horizontal"
        android:text="@string/vermas"
        android:textSize="12sp" />

    </LinearLayout>
</LinearLayout>

fragment.java

import java.util.HashMap;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.actionbarsherlock.app.SherlockFragment;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.InfoWindowAdapter;
import com.google.android.gms.maps.GoogleMap.OnInfoWindowClickListener;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;


public class Fragment3 extends SherlockFragment {
    //create hashmap
            private HashMap<Marker, Integer> hash = new HashMap<Marker, Integer>();
            private HashMap<Marker, Class<?>> hashclass = new HashMap<Marker, Class<?>>();


            @Override
            public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
                View rootView = inflater.inflate(R.layout.fragment3, null);
                return rootView;
            }

    @Override
    public void onViewCreated(View v, Bundle savedInstanceState){
        super.onViewCreated(v, savedInstanceState);

    final LatLng Initial = new LatLng(-34.673009, -58.474111);
    final LatLng FADU = new LatLng(-34.542163, -58.443716);
    final LatLng UNO = new LatLng(-34.533721, -58.508304);
    final LatLng DOSa = new LatLng(-34.664732, -58.360914);
    final LatLng DOSb = new LatLng(-34.620405, -58.371846);


GoogleMap googlemap;

        googlemap  = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map3)).getMap();

        googlemap.setMyLocationEnabled(true);
        googlemap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
        CameraUpdate update = CameraUpdateFactory.newLatLngZoom(Initial, 10);
        googlemap.animateCamera(update);


      //modify
            Marker marker1 = googlemap.addMarker(new MarkerOptions().position(FADU).title("FADU").snippet("Facultad de Arquitectura, Diseño y Urbanismo").icon(BitmapDescriptorFactory.fromResource(R.drawable.marker1)));
            hash.put(marker1, R.drawable.logo);
            hashclass.put(marker1, Contacto.class);


            googlemap.setOnInfoWindowClickListener(new OnInfoWindowClickListener(){

                @Override
                public void onInfoWindowClick(Marker marker) {
                    // TODO Auto-generated method stub
                    Class<?> cls = hashclass.get(marker);
                    Intent i = new Intent(getActivity(), cls);
                    startActivity(i);
                }
            });

            googlemap.setInfoWindowAdapter(new InfoWindowAdapter() {

                 @Override
                 public View getInfoWindow(Marker marker) {

                 View v =     getLayoutInflater(null).inflate(R.layout.infowindow, null);

             TextView titulo = (TextView) v.findViewById(R.id.titulo);
             TextView direccion = (TextView) v.findViewById(R.id.direccion);
                 ImageView imagen = ((ImageView)v.findViewById(R.id.imagen));

                 titulo.setText(marker.getTitle());
                 direccion.setText(marker.getSnippet());

                 if(hash.get(marker) != null)
                    imagen.setImageDrawable(getResources().getDrawable(hash.get(marker)));

                 return v;

                }
                //..
                 @Override
                    public View getInfoContents(Marker marker) {
                        // TODO Auto-generated method stub
                        return null;
                    }
                 });
                }

    @Override
    public void onPause() {
        super.onPause();

     }
    @Override
    public void onDestroyView() {

        super.onDestroyView(); 
        Fragment fragment = (getFragmentManager().findFragmentById(R.id.map3));  
        if (fragment != null){
            getActivity().getSupportFragmentManager().beginTransaction()
            .remove(fragment)
            .commit();          
            }      
    }
}

fragment.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

   <fragment
        android:id="@+id/map3"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment"/>

</RelativeLayout>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Android 2.x中的infowindow背景发生错误

来自分类Dev

在Android中使用KSOAP2时发生超时错误

来自分类Dev

在Android Studio中构建时,cocos2d-x项目给出了错误

来自分类Dev

cocos2d-x android编译错误

来自分类Dev

包含ListView maps v2 android的InfoWindow

来自分类Dev

Android Webview发生错误

来自分类Dev

Android Webview发生错误

来自分类Dev

我应该使用哪个android控件在android中获得2 x 2的可滚动网格?

来自分类Dev

Android中的ReCaptcha V2响应错误12008

来自分类Dev

使用kSOAP2在Android中获取错误

来自分类Dev

在ksoap 2 android中获取参数错误

来自分类Dev

Android Studio中构建gradle时出现2个错误

来自分类Dev

lambda 回调中 Android Cocos2D-x 应用程序上的段错误

来自分类Dev

如何修复Android中的“错误-无法执行tools \ android.bat,错误2”?

来自分类Dev

如何修复Android中的“错误-无法执行tools \ android.bat,错误2”?

来自分类Dev

Android 2.x中的重星号(u2731)

来自分类Dev

在Android Studio中打开cocos2d-x-3.7

来自分类Dev

在cocos2d-x中收听Android后退按钮

来自分类Dev

Android Dagger 2编译错误

来自分类Dev

建立android项目产生make错误2

来自分类Dev

Android Studio 2错误:app:compileDebugJavaWithJack

来自分类Dev

Android Studio Gradle CreateProcess错误= 2

来自分类Dev

Android上的Dagger 2,缺少错误消息

来自分类Dev

Android Studio 3.0 Canary 2 更新错误

来自分类Dev

Android Kotlin dagger 2 ViewModel 注入错误

来自分类Dev

android:retrofit2 发布错误但成功?

来自分类Dev

Android 2.x devanagari unicode问题

来自分类Dev

在x86_64 linux中重定位2GB以上的程序时发生链接器错误?

来自分类Dev

在Jenkins Linux EC2上的Android模拟器中安装APK时发生TimeoutException

Related 相关文章

热门标签

归档