私はアプリの画面の幅に一致するように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>
ここでは、問題の画像は、次のとおりです。
レイアウトでは、画像ビューに 'android:scaleType = "fitXY"プロパティを設定します。 –