类似于 google 地图的地图片段中的向上滑动面板
SlidingUp panel in map fragment similar to google maps
我正在使用它在我的地图片段中进行向上滑动布局,但我的应用程序一次又一次地崩溃,我不明白发生了什么。在错误报告中它只是说 Binary XML file line #34 Binary XML file line #34: "Error inflating class fragment".
这是我的MapsActivity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:app="http://schemas.android.com"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<com.sothree.slidinguppanel.SlidingUpPanelLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
app:umanoDragView="@+id/dragView"
app:umanoOverlay="true"
app:umanoPanelHeight="68dp"
app:umanoParalaxOffset="100dp"
app:umanoShadowHeight="4dp">
<android.support.v4.widget.DrawerLayout android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="#FFFFFF">
<ImageView
android:id="@+id/tree_button"
android:layout_width="40dp"
android:layout_height="40dp"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@drawable/tree" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Ecology"
android:textColor="@color/colorAccent"
android:textSize="30dp"
android:textStyle="bold" />
</android.support.v7.widget.Toolbar>
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity">
</fragment>
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="@menu/menu">
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
<include layout="@layout/bottom_data">
</include>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
</RelativeLayout>
BottomData.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:behavior_hideable="false"
android:clickable="true"
app:behavior_peekHeight="56dp"
app:layout_behavior="@string/bottom_sheet_behavior"
android:orientation="vertical">
<TextView
android:id="@+id/tex1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="EXPLORE "
android:textSize="30sp"
android:textStyle="bold" />
<Button
android:id="@+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tex1"
android:layout_centerInParent="true"
android:layout_marginTop="30dp"
android:text="Your Place" />
<Button
android:id="@+id/b2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/b1"
android:layout_centerInParent="true"
android:layout_marginTop="30dp"
android:text="My Place" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/b2"
android:layout_centerInParent="true"
android:layout_marginTop="30dp"
android:text="Many to find " />
</LinearLayout>
提前致谢!
试试这个代码..
Android工作室也提供地图activity..你可以轻松添加。
将以下依赖项添加到应用级别 gradle 文件中。
implementation 'com.google.android.gms:play-services-maps:16.1.0'
之后你的错误就解决了。
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
tools:context=".MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
我相信你使用 umano 滑块的方式不对。
com.sothree.slidinguppanel.SlidingUpPanelLayout
必须是 activity layout
中的 root element
layout
必须将 gravity
设置为 top
或 bottom
(滑块绘制的位置)
- 确保它有两个children。第一个 child 是你的
main layout
。第二个 child 是你的 layout
用于向上滑动面板
main layout
应将 width
和 height
设置为 match_parent
。
sliding layout
应将 width
设置为 match_parent
并将 height
设置为 match_parent
、wrap_content
这将是一个例子:
//main_activity.xml or whatever layout u wish
<com.sothree.slidinguppanel.SlidingUpPanelLayout
xmlns:sothree="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:umanoPanelHeight="68dp">//Height when the slide panel is in the collapsed form
//This is the base content, everything u want in the view has to be inside these
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
tools:context=".MapsActivity"
android:layout_width="match_parent"
android:layout_height="match_parent">
</fragment>
//This is the sliding layout, everything u want in the slider has to be here
<LinearLayout
android:id="@+id/slidingLayoutMapsFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|top"
android:text="The Awesome Sliding Up Panel"
android:textSize="16sp" />
</LinearLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
无论如何,你需要将其添加到 gradle 文件中
implementation 'com.sothree.slidinguppanel:library:3.4.0'
看这段代码
<com.sothree.slidinguppanel.SlidingUpPanelLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:sothree="http://schemas.android.com/tools"
android:gravity="bottom"
sothree:umanoPanelHeight="68dp"
sothree:umanoShadowHeight="4dp"
sothree:setAnchorPoint="middle"
>
<!-- Main here -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<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="com.eminent.a2019.mapslearnign.MapsActivity" />
</RelativeLayout>
<!-- SlideUpPanelHere -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
</LinearLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
我正在使用它在我的地图片段中进行向上滑动布局,但我的应用程序一次又一次地崩溃,我不明白发生了什么。在错误报告中它只是说 Binary XML file line #34 Binary XML file line #34: "Error inflating class fragment".
这是我的MapsActivity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:app="http://schemas.android.com"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<com.sothree.slidinguppanel.SlidingUpPanelLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
app:umanoDragView="@+id/dragView"
app:umanoOverlay="true"
app:umanoPanelHeight="68dp"
app:umanoParalaxOffset="100dp"
app:umanoShadowHeight="4dp">
<android.support.v4.widget.DrawerLayout android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="#FFFFFF">
<ImageView
android:id="@+id/tree_button"
android:layout_width="40dp"
android:layout_height="40dp"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@drawable/tree" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Ecology"
android:textColor="@color/colorAccent"
android:textSize="30dp"
android:textStyle="bold" />
</android.support.v7.widget.Toolbar>
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity">
</fragment>
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="@menu/menu">
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
<include layout="@layout/bottom_data">
</include>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
</RelativeLayout>
BottomData.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:behavior_hideable="false"
android:clickable="true"
app:behavior_peekHeight="56dp"
app:layout_behavior="@string/bottom_sheet_behavior"
android:orientation="vertical">
<TextView
android:id="@+id/tex1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="EXPLORE "
android:textSize="30sp"
android:textStyle="bold" />
<Button
android:id="@+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tex1"
android:layout_centerInParent="true"
android:layout_marginTop="30dp"
android:text="Your Place" />
<Button
android:id="@+id/b2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/b1"
android:layout_centerInParent="true"
android:layout_marginTop="30dp"
android:text="My Place" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/b2"
android:layout_centerInParent="true"
android:layout_marginTop="30dp"
android:text="Many to find " />
</LinearLayout>
提前致谢!
试试这个代码..
Android工作室也提供地图activity..你可以轻松添加。
将以下依赖项添加到应用级别 gradle 文件中。
implementation 'com.google.android.gms:play-services-maps:16.1.0'
之后你的错误就解决了。
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
tools:context=".MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
我相信你使用 umano 滑块的方式不对。
com.sothree.slidinguppanel.SlidingUpPanelLayout
必须是activity layout
中的 layout
必须将gravity
设置为top
或bottom
(滑块绘制的位置)- 确保它有两个children。第一个 child 是你的
main layout
。第二个 child 是你的layout
用于向上滑动面板 main layout
应将width
和height
设置为match_parent
。sliding layout
应将width
设置为match_parent
并将height
设置为match_parent
、wrap_content
root element
这将是一个例子:
//main_activity.xml or whatever layout u wish
<com.sothree.slidinguppanel.SlidingUpPanelLayout
xmlns:sothree="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:umanoPanelHeight="68dp">//Height when the slide panel is in the collapsed form
//This is the base content, everything u want in the view has to be inside these
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
tools:context=".MapsActivity"
android:layout_width="match_parent"
android:layout_height="match_parent">
</fragment>
//This is the sliding layout, everything u want in the slider has to be here
<LinearLayout
android:id="@+id/slidingLayoutMapsFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|top"
android:text="The Awesome Sliding Up Panel"
android:textSize="16sp" />
</LinearLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
无论如何,你需要将其添加到 gradle 文件中
implementation 'com.sothree.slidinguppanel:library:3.4.0'
看这段代码
<com.sothree.slidinguppanel.SlidingUpPanelLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:sothree="http://schemas.android.com/tools"
android:gravity="bottom"
sothree:umanoPanelHeight="68dp"
sothree:umanoShadowHeight="4dp"
sothree:setAnchorPoint="middle"
>
<!-- Main here -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<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="com.eminent.a2019.mapslearnign.MapsActivity" />
</RelativeLayout>
<!-- SlideUpPanelHere -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
</LinearLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>