【问题标题】:Resize height of Infowindow调整信息窗口的高度
【发布时间】:2016-08-24 07:13:07
【问题描述】:

我有一张 Google 地图,它在 InfoWindow 中显示当前位置和地名。它运行良好,但问题是当地方名称太长时,整个文本在 InfoWindow 中无法正确显示,如this。如何调整此信息窗口的大小? 我的代码如下:

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>

【问题讨论】:

    标签: android google-maps location infowindow


    【解决方案1】:

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

    解决方案 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)

    【讨论】:

    • 我的 info_window 布局包含 2 个 TextViews 所以第二个 textview 显示在 InfoWindow 之外!!!
    • 你能贴一张图片吗,因为我现在不能尝试这个?发布一个屏幕并说明它的 ID。
    • 能不能把info_window的xml也贴一下
    • 将相对布局高度从 margin_120 更改为 wrap_content
    猜你喜欢
    • 1970-01-01
    • 2011-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-14
    • 2016-07-08
    • 1970-01-01
    相关资源
    最近更新 更多