に変更できません.MapViewの高さを変更することはできません。 私が話していること:MapViewの高さを
fragment_map_view.xmlはmain_activity.xml viewpagerであるfragment_main_view.xmlです。
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
}
}
}
私はアイデアがありません、私が試したすべてのものは動作していません - 私はマップタブを選択しようとすると、アプリケーションは同じか、ちょうどクラッシュします。手伝ってくれてありがとう。
も方法 – Iriz