我想顯示在我的應用程序谷歌地圖的圖像,以便它匹配屏幕的寬度。 我使用DisplayMetrics作爲以下代碼,並將其傳遞給谷歌以獲取該大小的圖像(請參閱url參數)。但正如你在截圖中看到的那樣,它顯示錯誤的寬度。如何修復它?我認爲我發送的參數爲谷歌是不正確的?Android - 如何適合谷歌地圖圖像到屏幕寬度
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>
這裏是問題的圖像:
在layout中:在圖像視圖中設置屬性android:scaleType =「fitXY」。 –