2016-04-13 41 views
2

Bunu çözmek için bir fikrim yok, ben çekilebilir bir simge ve bir fiyat ile bir metin oluşturdum, bir metnin ortasında metni ortalayamıyorum [soldaki metinle simgeler küre i, merkez]Bir marker harita merkezinde orta metin android

public static Bitmap createTextMarker (Context context, String text) { 

    final Resources res = context.getResources(); 

    final int markerPadding = res.getDimensionPixelOffset(
     R.dimen.activity_maps_marker_padding); 

    final IconGenerator iconGenerator = new IconGenerator(context); 
    iconGenerator.setBackground(res.getDrawable(R.drawable.ic_marker_price1)); 
    iconGenerator.setTextAppearance(R.style.ParkingMarkerText); 


    iconGenerator.setContentPadding(markerPadding, 
     markerPadding + (markerPadding/3), 
    markerPadding, 0); 
    return iconGenerator.makeIcon(text); 

} 
+0

Düzeninizi XML'de yapmalısınız. Genellikle daha kolay ve Android Studio'daysanız değişiklikleri gerçek zamanlı olarak önizleyebilirsiniz. –

cevap

0

bu deneyin

kullanımını bu marker.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 

    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

     <ImageView 
      android:id="@+id/image" 
      android:layout_width="30dp" 
      android:layout_height="30dp" 
      android:src="@drawable/pin_new" /> 

     <TextView 
      android:id="@id/text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:layout_gravity="center" 
      android:paddingBottom="7dp" 
      android:textSize="12sp" 
      android:textStyle="bold" 
      android:textColor="@color/orange" /> 
    </RelativeLayout> 

</FrameLayout> 

ihtiyaç ve bu kodu ekleyin:

View markerView = mActivity.getLayoutInflater().inflate(R.layout.marker, null); 
iconGenerator.setContentView(markerView); 
+0

Tuval kullanamıyorum google maps api kullanıyorum. –

+0

Kodunu düzenledim –

+0

Bu bana simgelerin kenarlık beyazını yap :( –

2

Java kodunuzu, bunu yerine XML'ye çağırmak için değiştirmeniz gerekir. Pradep söyledi gibi, bu kodla bir marker.xml oluşturun:

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

<ImageView 
    android:id="@+id/MarkerIcon" 
    android:layout_width="fill_parent" 
    android:layout_height="250dp" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentRight="true" 
    android:scaleType="fitXY" 
    android:src="@drawable/ic_launcher" /> 

<TextView 
    android:id="@+id/priceTag" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_marginTop="20dp" 
    android:layout_centerHorizontal="true" /> 

</RelativeLayout> 

Sadece android:layout_marginTop="20dp" ve android:layout_height="250dp" daha iyi

.java parçası

View markerView = mActivity.getLayoutInflater().inflate(R.layout.marker, null); 
iconGenerator.setContentView(markerView); 
Bu ekle hangi değer giysileri görmek için değiştirmek

Ve "düzen" klasöründe "custom_marker_small" dosyasını iconGenerator.setBackground(res.getDrawable(R.drawable.ic_marker_price1));

+0

Bu değişiklikleri bugün yaptım ve işe yaramadı: / –

0

kaldırın. xml ":

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

    <ImageView 
     android:id="@+id/MarkerIcon" 
     android:layout_width="36dp" 
     android:layout_height="36dp" 
     android:src="@drawable/group_location_picker_1_5"/> 

    <TextView 
     android:id="@+id/priceTag" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:paddingTop="7dp" 
     android:text="77" 
     android:textColor="@color/white" 
     android:textSize="12sp"/> 

</RelativeLayout> 



IconGenerator generator = new IconGenerator(context); 

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View markerView = inflater.inflate(R.layout.custom_marker_small, null); 
      generator.setContentView(markerView); 
      generator.setBackground(null); 

    Bitmap icon = generator.makeIcon(); 
      markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));