ScrollView의 MapFragment
에 새로운 MapFragment
s 중 하나가 ScrollView
있습니다. 실제로는 SupportMapFragment
이지만 어쨌든. 작동하지만 두 가지 문제가 있습니다.
스크롤하면 뒤에 검은 마스크가 남습니다. 검은 색은 +/- 확대 / 축소 버튼이있는 구멍을 제외하고지도가 있던 영역을 정확히 덮습니다. 아래 스크린 샷을 참조하십시오. 이것은 Android 4.0에 있습니다.
requestDisallowInterceptTouchEvent()
사용자가ScrollView
가로 채기 터치 를 방지하기 위해지도와 상호 작용할 때보기가 사용되지 않으므로 지도에서 수직으로 이동하려고하면 포함 된ScrollView
. 이론적으로는 뷰 클래스를 파생하고MapView
해당 기능을 추가 할 수 있지만 표준 클래스 대신MapFragment
사용자 지정을 사용하려면 어떻게MapView
해야합니까?
맵뷰 조각에 투명한 이미지를 적용하면 문제가 해결되는 것 같습니다. 가장 예쁘지는 않지만 작동하는 것 같습니다. 다음은이를 보여주는 XML 스 니펫입니다.
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="300dp" >
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<ImageView
android:id="@+id/imageView123"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/temp_transparent" />
</RelativeLayout>
나를 위해 투명한 ImageView를 추가해도 검은 색 마스크를 완전히 제거하는 데 도움이되지 않았습니다. 스크롤하는 동안지도의 상단 및 하단 부분에 여전히 검은 색 마스크가 표시되었습니다.
그래서 그것에 대한 해결책은 이 답변 에서 작은 변화로 발견되었습니다 . 나는 추가했다,
android:layout_marginTop="-100dp"
android:layout_marginBottom="-100dp"
그것은 수직 스크롤 뷰이기 때문에 내지도 조각에. 이제 내 레이아웃은 다음과 같이 보입니다.
<RelativeLayout
android:id="@+id/map_layout"
android:layout_width="match_parent"
android:layout_height="300dp">
<fragment
android:id="@+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="-100dp"
android:layout_marginBottom="-100dp"
android:name="com.google.android.gms.maps.MapFragment"/>
<ImageView
android:id="@+id/transparent_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@color/transparent" />
</RelativeLayout>
질문의 두 번째 부분을 해결하기 위해 requestDisallowInterceptTouchEvent(true)
기본 ScrollView에 대해 설정 했습니다. 사용자는 투명 이미지를 만져 I가 투명 이미지에 터치를하지 않도록 이동하는 경우 MotionEvent.ACTION_DOWN
와 MotionEvent.ACTION_MOVE
터치 이벤트를 취할 수지도 조각 있도록.
ScrollView mainScrollView = (ScrollView) findViewById(R.id.main_scrollview);
ImageView transparentImageView = (ImageView) findViewById(R.id.transparent_image);
transparentImageView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
// Disallow ScrollView to intercept touch events.
mainScrollView.requestDisallowInterceptTouchEvent(true);
// Disable touch on transparent view
return false;
case MotionEvent.ACTION_UP:
// Allow ScrollView to intercept touch events.
mainScrollView.requestDisallowInterceptTouchEvent(false);
return true;
case MotionEvent.ACTION_MOVE:
mainScrollView.requestDisallowInterceptTouchEvent(true);
return false;
default:
return true;
}
}
});
이것은 나를 위해 일했습니다. 도움이 되었기를 바랍니다 ..
이것은 아마도이 질문 의 문제를 일으키는 동일한 장소에 뿌리를두고있을 것입니다 . 해결책은 투명한 이미지보다 약간 가벼운 투명한 프레임을 사용하는 것입니다.
많은 R & D 후 완료 :
fragment_one.xml은 다음과 같아야합니다.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scrollViewParent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="400dip" >
<com.google.android.gms.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<View
android:id="@+id/customView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/transparent" />
</RelativeLayout>
<!-- Your other elements are here -->
</LinearLayout>
</ScrollView>
FragmentOne.java의 Java 클래스는 다음과 같습니다.
private GoogleMap mMap;
private MapView mapView;
private UiSettings mUiSettings;
private View customView
onCreateView
mapView = (MapView) rootView.findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
if (mapView != null) {
mMap = mapView.getMap();
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
mUiSettings = mMap.getUiSettings();
mMap.setMyLocationEnabled(true);
mUiSettings.setCompassEnabled(true);
mUiSettings.setMyLocationButtonEnabled(false);
}
scrollViewParent = (ScrollView)rootView.findViewById(R.id.scrollViewParent);
customView = (View)rootView.findViewById(R.id.customView);
customView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
// Disallow ScrollView to intercept touch events.
scrollViewParent.requestDisallowInterceptTouchEvent(true);
// Disable touch on transparent view
return false;
case MotionEvent.ACTION_UP:
// Allow ScrollView to intercept touch events.
scrollViewParent.requestDisallowInterceptTouchEvent(false);
return true;
case MotionEvent.ACTION_MOVE:
scrollViewParent.requestDisallowInterceptTouchEvent(true);
return false;
default:
return true;
}
}
});
이 구조를 사용하여 문제를 극복했습니다.
지도 조각에 컨테이너 뷰를 사용했습니다.
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="Another elements in scroll view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.erolsoftware.views.MyMapFragmentContainer
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="250dp">
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/eventMap"
tools:context="com.erolsoftware.eventapp.EventDetails"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
</com.erolsoftware.views.MyMapFragmentContainer>
<TextView
android:text="Another elements in scroll view2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
컨테이너 클래스 :
public class MyMapFragmentContainer extends LinearLayout {
@Override
public boolean onInterceptTouchEvent(MotionEvent ev)
{
if (ev.getActionMasked() == MotionEvent.ACTION_DOWN)
{
ViewParent p = getParent();
if (p != null)
p.requestDisallowInterceptTouchEvent(true);
}
return false;
}
public MyMapFragmentContainer(Context context) {
super(context);
}
public MyMapFragmentContainer(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyMapFragmentContainer(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
}
customScrollViews 및 투명한 레이아웃 파일로 고생 할 필요가 없습니다. 더 가벼운 버전의 Google지도를 사용하면 문제가 해결됩니다.
map:liteMode="true"
레이아웃 파일의 맵 조각 안에 위의 속성을 추가하십시오. 문제가 해결됩니다.
질문의 두 번째 부분에서는 SupportMapFragment에서 조각 클래스를 파생시키고 대신 레이아웃에서 사용할 수 있습니다. 그런 다음 Fragment # onCreateView 를 재정의 하고 여기에서 사용자 지정 MapView를 인스턴스화 할 수 있습니다.
그래도 작동하지 않으면 언제든지 자신 만의 조각을 만들 수 있습니다. 모든 수명주기 메서드를 직접 호출하면됩니다 (onCreate, onResume 등). 이 답변 에는 더 자세한 내용이 있습니다.
<ScrollView
android:layout_width="match_parent"
::
::
::
<FrameLayout
android:id="@+id/map_add_business_one_rl"
android:layout_width="match_parent"
android:layout_height="100dp"
>
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="-100dp"
android:layout_marginBottom="-100dp"
/>
</FrameLayout>
::
::
::
</ScrollView>
참조 URL : https://stackoverflow.com/questions/13746351/mapfragment-in-scrollview
'IT이야기' 카테고리의 다른 글
Javafx 2 클릭 및 더블 클릭 (0) | 2021.03.24 |
---|---|
Google 크롬 비활성화 화면 눈금자 (0) | 2021.03.24 |
jacoco.exec 보고서 사용 방법 (0) | 2021.03.24 |
페이지로드 속도를 최적화하려면 모든 CSS 파일을 프로그래밍 방식으로 인라인 해야 할까? (0) | 2021.03.24 |
asp.net 애플리케이션에서 C#7 활성화 (0) | 2021.03.24 |