Issue
as it's in title - i can't change MapView height. Whats i'm talking about:
fragment_map_view.xml is in fragment_main_view.xml which is in main_activity.xml viewpager.
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
}
}
}
I'm out of ideas, every thing i tried isn't working - App looks the same or just crash when i try to pick map tab. Thanks for help.
Solution
In your fragment_map_view , set
android:fillViewPort="true"
to your scrollView and map will appear in full layout.
Answered By - Muhib Pirani
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.