首页 > 解决方案 > 为什么缩放在 Android Coordinator Layout 中不起作用?

问题描述

我希望将持久的底部对话框添加到我的 Android 地图应用程序中,并已开始修改我的 activity.xml 布局文件。但是,我发现捏放大/缩小和缩放 +/- 控件不起作用。唯一起作用的是圆形“重新定位到当前位置”按钮(通常位于屏幕右上角的那个。

我的原始xml文件如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1"
android:id="@+id/tlll"
>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/llhelpgraphic"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight=".08"
    android:background="#000000"
    android:orientation="horizontal">

    <ImageButton
        android:id="@+id/helpButton"
        android:layout_height="match_parent"
        android:layout_width="wrap_content"
        android:layout_margin="3dp"
        android:adjustViewBounds="true"
        android:src="@drawable/help5"
        />

    <ImageView
        android:id="@+id/titleview"
        android:layout_height="match_parent"
        android:layout_width="fill_parent"
        android:layout_weight="1"
        android:src="@drawable/title"
        />

</LinearLayout>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/frlayout"
    android:layout_weight=".82"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    >

    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:map="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".FindIt" />

</FrameLayout>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight=".10"
    android:background="#004D79"
    android:orientation="horizontal">

    <EditText
        android:id="@+id/addressText"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="7dp"
        android:layout_weight="1"
        android:background="#FFFFFF"
        android:text="Enter UK address or postcode">
    </EditText>

    <Button
        android:id="@+id/findButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:text="Find">
    </Button>
</LinearLayout>

我修改后的文件如下:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/bgLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1"
android:id="@+id/tlll"
>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/llhelpgraphic"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight=".08"
    android:background="#000000"
    android:orientation="horizontal">

    <ImageButton
        android:id="@+id/helpButton"
        android:layout_height="match_parent"
        android:layout_width="wrap_content"
        android:layout_margin="3dp"
        android:adjustViewBounds="true"
        android:src="@drawable/help5"
        />

    <ImageView
        android:id="@+id/titleview"
        android:layout_height="match_parent"
        android:layout_width="fill_parent"
        android:layout_weight="1"
        android:src="@drawable/title"
        />

</LinearLayout>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/frlayout"
    android:layout_weight=".82"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    >

    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:map="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".FindIt" />

</FrameLayout>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight=".10"
    android:background="#004D79"
    android:orientation="horizontal">

    <EditText
        android:id="@+id/addressText"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="7dp"
        android:layout_weight="1"
        android:background="#FFFFFF"
        android:text="Enter UK address or postcode">
    </EditText>

    <Button
        android:id="@+id/findButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:text="Find">
    </Button>
</LinearLayout>

</LinearLayout>
<android.support.v4.widget.NestedScrollView
    android:id="@+id/loclistdialog"
    android:layout_width="match_parent"
    android:layout_height="250dp"
    android:clipToPadding="true"
  app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:text=""
            android:id="@+id/loclist"
            />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

我所做的唯一更改是将 CoordinatorLayout 和 NestedScrollView 添加到文件中。有人可以帮忙吗?

标签: androidandroid-coordinatorlayoutandroid-nestedscrollview

解决方案


推荐阅读