调整Infowindow的高度

时间:2016-08-24 07:13:07

标签: android google-maps location infowindow

我有一张Google地图,它在InfoWindow中显示当前位置和地点名称。它运行良好,但问题是当地名太长时,整个文本在InfoWindow中没有正确显示,如this。我怎样才能调整这个Infowindow的大小?   我的代码如下:

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

我的xml在

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

1 个答案:

答案 0 :(得分:0)

您已为整个布局设置了静态宽度。

解决方案1 ​​

更改

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

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

解决方案2

通过将maxLines设置为2或3来创建textView多线 比如txtTitle.setMaxLines(2)