2017-04-18 114 views
0

我在我的Android应用程序mapbox地图,但它总是占据了整个屏幕。我想让它和下面的内容一样大。Mapbox地图占据整个屏幕

这里是我的代码(设定一个固定的大小也不起作用):

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="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:fitsSystemWindows="true" 
tools:context="com.travip.MainActivity"> 

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     app:popupTheme="@style/AppTheme.PopupOverlay" /> 

</android.support.design.widget.AppBarLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

    <com.mapbox.mapboxsdk.maps.MapView 
     android:id="@+id/mapview" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"/> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:text="Hello" /> 

</LinearLayout> 

+0

你能分享你的布局文件吗?你应该能够在Mapbox Mapview上设置一个固定的大小。 – Tobrun

回答

1

变化

android:layout_height="wrap_content" 

android:layout_height="match_parent"

线性布局

0

谢谢您的帮助! 我不小心叫

View rootView = inflater.inflate(R.layout.fragment_map, container, false); 

而不是

View rootView = inflater.inflate(R.layout.fragment_nearby, container, false); 

我的片段充气错布局。我没有注意到,因为它们看起来几乎一样