2016-04-23 18 views
0

私はアプリの画面の幅に一致するようにGoogleマップの画像を表示しようとしています。 DisplayMetricsを次のコードとして使用し、そのサイズでイメージを取得するためにgoogleに渡しました(URLパラメータを参照)。スクリーンショットで見ることができるように、間違った幅が表示されます。どのようにそれを修正?私はGoogle用のパラメータで送信するものは正しくないと思いますか?アンドロイド - どのように画面の幅に合わせてGoogleマップ画像

DisplayMetrics displaymetrics = new DisplayMetrics(); 
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); 
int heightP = (int) displaymetrics.heightPixels; 
int widthP = (int) displaymetrics.widthPixels; 
int height = (int) (displaymetrics.heightPixels/displaymetrics.density); 
int width = (int) (displaymetrics.widthPixels/displaymetrics.density); 

................ 

    ImageView imgImage = (ImageView) findViewById(R.id.imgImage); 
    //TextView txtDetail = (TextView) findViewById(R.id.txtDetail); 

    imgImage.getLayoutParams().width = LayoutParams.MATCH_PARENT; 
    imgImage.getLayoutParams().height = (height/2); 
............... 

     ImageView gmap = (ImageView) findViewById(R.id.googlemap); 
     gmap.getLayoutParams().height = 200; 
     //gmap.requestLayout(); 
     String url = "http://maps.google.com/maps/api/staticmap?center=" + estate.getString("maplat") + "," + estate.getString("maplng") + "&zoom=" + estate.getString("mapzoom") + "&size=" + Integer.toString(widthP - 10) + "x200&sensor=false&format=jpeg&&markers=color:red|" + estate.getString("maplat") + "," + estate.getString("maplng"); 

     Picasso.with(this) 
       .load(url) 
       .placeholder(R.drawable.animated_progress) 
       .into(gmap); 

レイアウト:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/detailLayer" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layoutDirection="rtl" 
    android:padding="8dp" 
    tools:context=".DetailActivity"> 


    <ScrollView 
     android:id="@+id/scrollview1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:textAlignment="gravity" 
      android:textDirection="rtl"> 

      <Button 
       android:id="@+id/btnEdit" 
       style="@style/CKButton" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="12dp" 
       android:text="@string/txt_manage" 
       android:visibility="gone" /> 

      <ImageView 
       android:id="@+id/imageView1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="-50dp" 
       android:src="@drawable/sold" 
       android:visibility="gone" /> 


      <ImageView 
       android:id="@+id/imgImage" 
       android:layout_width="match_parent" 
       android:layout_height="300dp" 
       android:clickable="true" 
       android:paddingBottom="8dp" 
       android:paddingTop="8dp" 
       android:scaleType="centerCrop" 
       android:textAlignment="gravity" /> 


</ScrollView> 

</FrameLayout> 

ここでは、問題の画像は、次のとおりです。

here is issue

+0

レイアウトでは、画像ビューに 'android:scaleType = "fitXY"プロパティを設定します。 –

答えて

0

はあなたのImageViewの中でプロパティandroid:scaleType="fitXY"を設定してください。 XMLを使用することにより

0

、単に属性を入れて、あなたのImageViewのに

android:scaleType="fitXY" 

。あなたは間違っている濃度画素の画像幅を送信しているため、Javaのことで

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    **android:scaleType="fitXY"** 
    android:src="@drawable/logo" /> 

imageview.setScaleType(ScaleType.FIT_XY); 
0

のようにはい、あなたのurlパラメータは真実ではありません。

あなたのURLでは、dp(密度ピクセル)値ではなく、ピクセル値だけを渡す必要があります。

google map urlの詳細については、this docをお読みください。

どのタイプのパラメータを送信して、より正確な地図画像のサイズを取得するのに役立ちます。

screen_width = getResources().getDisplayMetrics().widthPixels; 

String url = "http://maps.google.com/maps/api/staticmap?center=" + estate.getString("maplat") + "," + estate.getString("maplng") + "&zoom=" + estate.getString("mapzoom") + "&size=" + Integer.toString(screen_width - 10) + "x200&sensor=false&format=jpeg&&markers=color:red|" + estate.getString("maplat") + "," + estate.getString("maplng"); 

あなたのURLにこれを渡してください。

関連する問題