2016-08-24 3 views
0

Ich habe eine Google Map, die den aktuellen Standort und Ortsnamen in InfoWindow zeigt. Es funktioniert gut, aber das Problem ist, wenn der Ortsname zu lang ist, zu diesem Zeitpunkt wird der gesamte Text nicht korrekt in InfoWindow wie this angezeigt. Wie kann ich dieses Infofenster anpassen? Mein Code ist unten:Höhe der Infowindow ändern

private class CustomInfoWindowAdapter implements GoogleMap.InfoWindowAdapter { 

     private View view; 

     public CustomInfoWindowAdapter() { 
      view = getLayoutInflater().inflate(R.layout.info_window, null); 

      view.setLayoutParams(new RelativeLayout.LayoutParams(500, RelativeLayout.LayoutParams.WRAP_CONTENT)); 
     } 

     @Override 
     public View getInfoContents(Marker marker) { 

      if (CheckIn.this.marker != null && CheckIn.this.marker.isInfoWindowShown()) { 
       CheckIn.this.marker.hideInfoWindow(); 
       CheckIn.this.marker.showInfoWindow(); 
      } 
      return null; 
     } 

     @Override 
     public View getInfoWindow(final Marker marker) { 
      CheckIn.this.marker = marker; 

      String url = null, isLoaded = "0"; 

      /*if (marker.getId() != null && markers != null && markers.size() > 0) { 
       if (markers.get(marker.getId()) != null && markers.get(marker.getId()) != null) { 
        url = markers.get(marker.getId()); 
        isLoaded = markers.get(marker.getId() + marker.getTitle()); 
       } 
      }*/ 
      final ImageView imgAddress = ((ImageView) view.findViewById(R.id.imgAddress)); 

      final String title = marker.getTitle(); 

      final CustomTextView txtTitle = ((CustomTextView) view.findViewById(R.id.txtTitle)); 
      if (title != null) { 
       /*txtTitle.setText("La Brasserie Bordelaise");*/ 
       mProgressDialog.dismiss(); 
       txtTitle.setText(currentPlaceName); 
       txtTitle.setOnClickListener(new View.OnClickListener() { 
        @Override 
        public void onClick(View v) { 
         Toast.makeText(CheckIn.this, title, Toast.LENGTH_LONG).show(); 
        } 
       }); 
      } else { 
       txtTitle.setText(""); 
      } 

      return view; 
     } 
    } 

meine xml unter

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


    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="@dimen/margin_120" 
     android:layout_centerHorizontal="true" 
     android:layout_marginLeft="@dimen/margin_30" 
     android:layout_marginRight="@dimen/margin_30" 
     android:background="@drawable/bg_info_window"> 

     <RelativeLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="@dimen/margin_5"> 

      <RelativeLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="3dp" 
       android:layout_marginLeft="@dimen/margin_5" 
       android:layout_marginRight="@dimen/margin_5" 
       android:layout_toLeftOf="@+id/imgAddress"> 

       <com.widget.CustomTextView 
        android:id="@+id/txtTitle" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="5dp" 
        android:inputType="textMultiLine" 
        android:maxLines="2" 
        android:singleLine="false" 
        android:text="aaaa" 
        android:textColor="@android:color/black" 
        android:textSize="@dimen/text_size_16" 
        customFont:fontTextStyle="3" /> 
       <!--android:text="La Brasserie Bordelaise"--> 


       <LinearLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_below="@+id/txtTitle" 
        android:layout_marginLeft="@dimen/margin_5" 
        android:orientation="horizontal"> 

        <ImageView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_marginTop="@dimen/margin_5" 
         android:src="@drawable/ic_person" /> 

        <com.widget.CustomTextView 
         android:id="@+id/txtTotalPeople" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_marginLeft="5dp" 
         android:inputType="textMultiLine" 
         android:singleLine="false" 
         android:text="aaaa" 
         android:textColor="@color/colorDetailGray" 
         android:textSize="@dimen/text_size_medium" 
         customFont:fontTextStyle="3" /> 
       </LinearLayout> 
      </RelativeLayout> 

      <ImageView 
       android:id="@+id/imgAddress" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentRight="true" 
       android:layout_centerVertical="true" 
       android:contentDescription="@string/app_name" 
       android:padding="@dimen/padding_10" 
       android:src="@drawable/ic_right_arrow" /> 
     </RelativeLayout> 
    </RelativeLayout> 
</RelativeLayout> 

Antwort

0

Sie eine statische Breite für das gesamte Layout festgelegt hast.

Lösung 1

ändern

view.setLayoutParams(new RelativeLayout.LayoutParams(500, RelativeLayout.LayoutParams.WRAP_CONTENT)); 

Um

view.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT)); 

Lösung 2

Machen Sie das Textview mehrzeilige durch maxLines Einstellung als 2 oder 3 wie txtTitle.setMaxLines(2)

+0

Entschuldigung !!! Es funktioniert nicht für mich !!! –

+0

Mein info_window Layout enthält 2 TextViews Also zweite Textansicht aus InfoWindow !!! –

+0

Kannst du ein Bild posten, da ich das jetzt nicht ausprobieren kann? Veröffentlichen Sie einen Bildschirm und geben Sie die ID dafür an. –

Verwandte Themen