2016-07-27 6 views
2

Google MapScrollViewの中に使いたいと思っていましたが、思ったより難しいようです。初めて私はすべてを作り、タブレットでアプリを走らせました。タブレットでは、UIが地図のサイズを上回り、場所が完璧です。小さなデバイスを試してみると、地図の80%のサイズが見えないことに気付きました。私は画面の終わりまでスクロールすることができますが、残りの地図の代わりに大きな空の場所があります。SrcollViewの中に完全な地図を表示するandroid

チェック以下の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:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fillViewport="true" 
android:id="@+id/scrollView"> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/background" 
    android:id="@+id/relativeinfo1"> 

<View 
    android:layout_width="wrap_content" 
    android:layout_height="35dp" 
    android:layout_above="@+id/titleinfo" 
    android:layout_toRightOf="@+id/imageinfo"/> 


<TextView 
    android:id="@+id/titleinfo" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="30dp" 
    android:textSize="20dp" 
    android:textStyle="bold" 
    android:textColor="#000000" 
    android:layout_toRightOf="@+id/imageinfo" 
    android:layout_marginLeft="20dp"/> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:autoLink="phone" 
    android:id="@+id/mooobil"/> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:autoLink="phone" 
    android:id="@+id/telefoneeo"/> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:autoLink="email" 
    android:id="@+id/emailese"/> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:autoLink="web" 
    android:id="@+id/honlapese"/> 


<ImageView 
    android:layout_width="60dp" 
    android:layout_height="60dp" 
    android:id="@+id/imageinfo" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:layout_marginLeft="10dp" 
    android:layout_marginTop="10dp"/> 

<View 
    android:layout_width="wrap_content" 
    android:layout_height="15dp" 
    android:id="@+id/view1" 
    android:layout_below="@+id/imageinfo"/> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/cimtext" 
    android:textStyle="bold" 
    android:text="Cím: " 
    android:textSize="15dp" 
    android:textColor="#000000" 
    android:visibility="invisible"/> 


<View 
    android:layout_width="wrap_content" 
    android:layout_height="10dp" 
    android:id="@+id/vonal" 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="10dp" 
    android:background="#FFD700" /> 

<View 
    android:layout_width="wrap_content" 
    android:layout_height="10dp" 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="10dp" 
    android:id="@+id/vonal2" 
    android:background="#FFD700"/> 



<RelativeLayout 
    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" 
    tools:context=".MainActivity" 
    android:id="@+id/relativemaplayout" 
    android:clickable="true" 
    android:background="#000000"> 

    <fragment 
     android:id="@+id/map" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" 
     android:layout_marginTop="10dp" 
     class="com.google.android.gms.maps.MapFragment" /> 


</RelativeLayout> 
</RelativeLayout> 

そしてここでJavaコードをチェックしてください。

private ScrollView mScrollView; 

public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) { 
    View v = inflater.inflate(R.layout.activity_service_info,parent, false); 
    mScrollView = (ScrollView) v.findViewById(R.id.scrollView); 
    //transparentImageView = (ImageView) v.findViewById(R.id.transparent_image); 
    mScrollView.requestDisallowInterceptTouchEvent(true); 

    ///// MAP ///// 
    double glat = 0; 
    double glong = 0; 


    map = ((MapFragment) getActivity().getFragmentManager().findFragmentById(R.id.map)).getMap(); 

    if((si.getGpslat().length()) != 0 && (si.getGpslong().length() != 0)){ 
     glat = Double.parseDouble(si.getGpslat()); 
     glong = Double.parseDouble(si.getGpslong()); 

     final LatLng CEL = new LatLng(glat,glong); 

     if (map!=null){ 
      MapsInitializer.initialize(getActivity()); 
      map.addMarker(new MarkerOptions().position(CEL)); 
      map.moveCamera(CameraUpdateFactory.newLatLngZoom(CEL ,18)); 
      map.animateCamera(CameraUpdateFactory.zoomTo(18), 2000, null); 
     } 

    }else{ 
     relmap.setVisibility(View.GONE); 
    } 


    transparentImageView.setOnTouchListener(new View.OnTouchListener() { 

     @Override 
     public boolean onTouch(View v, MotionEvent event) { 
      int action = event.getAction(); 
      Log.d("action","down"); 
      switch (action) { 
       case MotionEvent.ACTION_DOWN: 
        // Disallow ScrollView to intercept touch events. 
        mScrollView.requestDisallowInterceptTouchEvent(true); 
        Log.d("action","down"); 
        return false; 

       case MotionEvent.ACTION_UP: 
        // Allow ScrollView to intercept touch events. 
        mScrollView.requestDisallowInterceptTouchEvent(false); 
        Log.d("action","up"); 
        return true; 

       case MotionEvent.ACTION_MOVE: 
        mScrollView.requestDisallowInterceptTouchEvent(true); 
        Log.d("action","move"); 
        return false; 

       default: 
        return true; 
      } 
     } 
    }); 

    transparentImageView.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      Toast.makeText(getActivity(), "anyád", Toast.LENGTH_SHORT).show(); 
     } 
    }); 
    return v; 
} 

それはタブレットを使用せずにSrcollViewで完全な地図を表示することは可能ですか?私はいくつかの測定誤差の原因となるfragment.Thatためので、あなたのlayout_heightのそれ `sは設定考える

enter image description here

+0

はあなたが投稿することができます1つの画面の短い、私はどのように見てみましょう –

+0

は、スクリーンショットを追加することができます – DKV

+0

はいスクリーンショットを追加しました。 –

答えて

0

てみてください。

<?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:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fillViewport="true" 
android:id="@+id/scrollView"> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/background" 
    android:id="@+id/relativeinfo1"> 


<View 
    android:layout_width="wrap_content" 
    android:layout_height="35dp" 
    android:layout_above="@+id/titleinfo" 
    android:layout_toRightOf="@+id/imageinfo"/> 


<TextView 
    android:id="@+id/titleinfo" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="30dp" 
    android:textSize="20dp" 
    android:textStyle="bold" 
    android:textColor="#000000" 
    android:layout_toRightOf="@+id/imageinfo" 
    android:layout_marginLeft="20dp"/> 


    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:autoLink="phone" 
     android:id="@+id/cimtext"/> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:autoLink="phone" 
    android:id="@+id/mooobil"/> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:autoLink="phone" 
    android:id="@+id/telefoneeo"/> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:autoLink="email" 
    android:id="@+id/emailese"/> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:autoLink="web" 
    android:id="@+id/honlapese"/> 


<ImageView 
    android:layout_width="60dp" 
    android:layout_height="60dp" 
    android:id="@+id/imageinfo" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:layout_marginLeft="10dp" 
    android:layout_marginTop="10dp"/> 

<View 
    android:layout_width="wrap_content" 
    android:layout_height="15dp" 
    android:id="@+id/view1" 
    android:layout_below="@+id/imageinfo"/> 


<View 
    android:layout_width="wrap_content" 
    android:layout_height="10dp" 
    android:id="@+id/vonal" 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="10dp" 
    android:background="#FFD700" /> 

<View 
    android:layout_width="wrap_content" 
    android:layout_height="10dp" 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="10dp" 
    android:id="@+id/vonal2" 
    android:background="#FFD700"/> 

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="wrap_content" 
    android:layout_height="400dp" 
    tools:context=".MainActivity" 
    android:id="@+id/relativemaplayout" 
    android:clickable="true"> 

    <fragment 
     android:id="@+id/map" 
     android:layout_width="wrap_content" 
     android:layout_height="400dp" 
     android:layout_marginLeft="10dp" 
     android:layout_marginTop="10dp" 
     android:layout_marginRight="5dp" 
     class="com.google.android.gms.maps.MapFragment" /> 

</RelativeLayout> 


    <ImageView 
     android:id="@+id/transparent_image" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@color/transparent" 
     android:layout_alignTop="@+id/relativemaplayout" 
     android:layout_alignBottom="@+id/relativemaplayout" 
     android:layout_alignEnd="@+id/relativemaplayout" 
     android:layout_alignRight="@+id/relativemaplayout" 
     android:layout_alignLeft="@+id/relativemaplayout" 
     android:layout_alignStart="@+id/relativemaplayout"/> 
</RelativeLayout> 

そして、あなたは、フラグメントにこれを追加する必要があります。

transparentImageView.setOnTouchListener(new View.OnTouchListener() { 
     @Override 
     public boolean onTouch(View v, MotionEvent event) { 
      int action = event.getAction(); 
      Log.d("action","down"); 
      switch (action) { 
       case MotionEvent.ACTION_DOWN: 
        // Disallow ScrollView to intercept touch events. 
        mScrollView.requestDisallowInterceptTouchEvent(true); 
        Log.d("action","down"); 
        return false; 

       case MotionEvent.ACTION_UP: 
        // Allow ScrollView to intercept touch events. 
        mScrollView.requestDisallowInterceptTouchEvent(false); 
        Log.d("action","up"); 
        return true; 

       case MotionEvent.ACTION_MOVE: 
        mScrollView.requestDisallowInterceptTouchEvent(true); 
        Log.d("action","move"); 
        return false; 

       default: 
        return true; 
      } 
     } 
    }); 
0

次のようになります方法です。

layout_heightを特定のdpに設定してみてください。など

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="300dp" 
tools:context=".MainActivity" 
android:id="@+id/relativemaplayout" 
android:clickable="true" 
android:background="#000000"> 

<fragment 
    android:id="@+id/map" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="10dp" 
    android:layout_marginTop="10dp" 
    class="com.google.android.gms.maps.MapFragment" /> 

+0

残念ながら、それは良い解決策ではありません。 –

1

まだあなたがPROBを持っている場合は、この

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#ff0000" 
    android:id="@+id/relativeinfo1"> 

    <View 
     android:layout_width="wrap_content" 
     android:layout_height="35dp" 
     android:layout_above="@+id/titleinfo" 
     android:layout_toRightOf="@+id/imageinfo"/> 


    <TextView 
     android:id="@+id/titleinfo" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="30dp" 
     android:textSize="20dp" 
     android:textStyle="bold" 
     android:textColor="#000000" 
     android:layout_toRightOf="@+id/imageinfo" 
     android:layout_marginLeft="20dp"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:autoLink="phone" 
     android:id="@+id/mooobil"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:autoLink="phone" 
     android:id="@+id/telefoneeo"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:autoLink="email" 
     android:id="@+id/emailese"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:autoLink="web" 
     android:id="@+id/honlapese"/> 


    <ImageView 
     android:layout_width="60dp" 
     android:layout_height="60dp" 
     android:id="@+id/imageinfo" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginLeft="10dp" 
     android:layout_marginTop="10dp"/> 

    <View 
     android:layout_width="wrap_content" 
     android:layout_height="15dp" 
     android:id="@+id/view1" 
     android:layout_below="@+id/imageinfo"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/cimtext" 
     android:textStyle="bold" 
     android:text="Cím: " 
     android:textSize="15dp" 
     android:textColor="#000000" 
     android:visibility="invisible"/> 


    <View 
     android:layout_width="wrap_content" 
     android:layout_height="10dp" 
     android:id="@+id/vonal" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" 
     android:background="#FFD700" /> 

    <View 
     android:layout_width="wrap_content" 
     android:layout_height="10dp" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" 
     android:id="@+id/vonal2" 
     android:background="#FFD700"/> 


    <RelativeLayout 
     android:layout_alignParentBottom="true" 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     tools:context=".MainActivity" 
     android:id="@+id/relativemaplayout" 
     android:clickable="true" 
     android:background="#000000"> 

     <fragment 
      android:id="@+id/map" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="10dp" 
      class="com.google.android.gms.maps.MapFragment" /> 


    </RelativeLayout> 
</RelativeLayout> 

更新

のようなお試しくださいLEMこれを参照し、これが解決した

Google Maps API v2 SupportMapFragment inside ScrollView - users cannot scroll the map vertically

+0

今私は下にスクロールすることができないので、私はマップの一番上しか見ることができません。地図のサイズは以前と同じです。 –

+0

フラグメントの幅を android:layout_height = "match_content" –

+0

に変更しようとしました –

関連する問題