2017-05-12 1 views
1

wie es in Titel ist - ich kann MapView Höhe nicht ändern. Worüber ich rede:MapView height kann nicht geändert werden

Screen 1 | Screen 2

fragment_map_view.xml ist in fragment_main_view.xml die in main_activity.xml viewpager ist.

fragment_map_view.xml:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/startview" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <com.google.android.gms.maps.MapView 
     android:id="@+id/map" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 

</ScrollView> 

fragment_main_view.xml:

<FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.trattoria.restaurant_app.activities.MainFragmentActivity" 
    tools:ignore="MergeRootFrame"/> 

main_activity:

<com.trattoria.restaurant_app.widgets.TouchCallbackLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@id/layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:id="@id/header" 
     android:background="@color/colorPrimary" 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <TextView 
      android:gravity="center_vertical" 
      android:paddingLeft="@dimen/space_middle" 
      android:paddingRight="@dimen/space_middle" 
      android:textColor="@android:color/white" 
      android:text="@string/header_text" 
      android:textStyle="bold" 
      android:textSize="18sp" 
      android:layout_width="match_parent" 
      android:layout_height="@dimen/viewpager_header_height"/> 

     <com.trattoria.restaurant_app.widgets.SlidingTabLayout 
      android:id="@id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="@dimen/tabs_height"/> 
    </LinearLayout> 

    <android.support.v4.view.ViewPager 
     android:id="@id/viewpager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="@dimen/tabs_height"/> 

</com.trattoria.restaurant_app.widgets.TouchCallbackLayout> 

MapViewFragment.java:

import android.os.Bundle; 
import android.view.LayoutInflater; 
import android.view.MotionEvent; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.ScrollView; 

import com.google.android.gms.maps.MapView; 
import com.google.android.gms.maps.MapsInitializer; 
import com.google.android.gms.maps.model.CameraPosition; 
import com.trattoria.restaurant_app.R; 
import com.trattoria.restaurant_app.delegate.ScrollViewDelegate; 
import com.google.android.gms.maps.CameraUpdateFactory; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.OnMapReadyCallback; 
import com.google.android.gms.maps.model.LatLng; 
import com.google.android.gms.maps.model.MarkerOptions; 


import java.io.ByteArrayOutputStream; 
import java.io.Closeable; 
import java.io.InputStream; 

public class MapViewFragment extends BaseViewPagerFragment 
     implements OnMapReadyCallback 
{ 

    GoogleMap mGoogleMap; 
    MapView mMapView; 
    View mView; 
    private ScrollView mScrollView; 
    private ScrollViewDelegate mScrollViewDelegate = new ScrollViewDelegate(); 


    public static MapViewFragment newInstance(int index) 
    { 
     MapViewFragment fragment = new MapViewFragment(); 
     Bundle args = new Bundle(); 
     args.putInt(BUNDLE_FRAGMENT_INDEX, index); 
     fragment.setArguments(args); 
     return fragment; 
    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) 
    { 
     mView = inflater.inflate(R.layout.fragment_map_view, container, false); 
     mScrollView = (ScrollView) mView.findViewById(R.id.startview); 

     return mView; 
    } 

    @Override 
    public void onViewCreated(View view, Bundle savedInstanceState) 
    { 
     super.onViewCreated(view, savedInstanceState); 

     mMapView = (MapView) mView.findViewById(R.id.map); 
     if(mMapView != null) 
     { 
      mMapView.onCreate(null); 
      mMapView.onResume(); 
      mMapView.getMapAsync(this); 
     } 
    } 

    @Override 
    public void onMapReady(GoogleMap googleMap) 
    { 
     MapsInitializer.initialize(getContext()); 

     mGoogleMap = googleMap; 
     googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); 

     googleMap.addMarker(new MarkerOptions() 
       .position(new LatLng(40.689247, -74.044502)) 
       .title("Statue of Liberty") 
       .snippet("SAMPEL POJNT")); 

     CameraPosition Liberty = CameraPosition.builder() 
       .target(new LatLng(40.689247, -74.044502)) 
       .zoom(16) 
       .bearing(0) 
       .tilt(45) 
       .build(); 

     googleMap.moveCamera(CameraUpdateFactory.newCameraPosition(Liberty)); 
    } 

    @Override 
    public boolean isViewBeingDragged(MotionEvent event) 
    { 
     return mScrollViewDelegate.isViewBeingDragged(event, mScrollView); 
    } 

    private String loadContentString() 
    { 
     InputStream inputStream = null; 
     ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); 
     byte buf[] = new byte[8 * 1024]; 
     int len; 
     String content = ""; 
     try 
     { 
      inputStream = getActivity().getAssets().open("start.txt"); 
      while ((len = inputStream.read(buf)) != -1) 
      { 
       outputStream.write(buf, 0, len); 
      } 
      content = outputStream.toString(); 
     } catch (Exception e) 
     { 
      e.printStackTrace(); 
     } finally 
     { 
      closeSilently(inputStream); 
      closeSilently(outputStream); 
     } 

     return content; 
    } 

    public void closeSilently(Closeable c) 
    { 
     if (c == null) 
     { 
      return; 
     } 
     try 
     { 
      c.close(); 
     } catch (Throwable t) 
     { 
      // do nothing 
     } 
    } 
} 

Ich habe keine Ideen mehr, alles, was ich ausprobiert habe, funktioniert nicht - App sieht genauso aus oder stürzt einfach ab, wenn ich versuche, einen Karteireiter auszuwählen. Danke für die Hilfe.

Antwort

0

In Ihrem fragment_map_view setzten

android:fillViewPort="true" 

auf Ihre Scrollview und Karte wird in vollem Layout erscheinen.

+0

Thank you Es ist! arbeiten! c: – Iriz

0

Sie können die Layouthöhe und das Gewicht manuell wie Android: layout_width = "200dp" android: layout_height = "100dp" statt übergeordnete übergeordnete festlegen.

+0

ich schon versucht, diese vor, aber ohne Ergebnis :( android: fillViewPort = „true“ mein Problem gelöst – Iriz

+0

gut, das auch ein Verfahren –

0

Einstellhöhe nach onResume() hat für mich gearbeitet

mapView.onResume() 
mapView.layoutParams = ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, 
            view.context.dpToPx(120f) 
) 
Verwandte Themen