0

正方形の画像 (約 315 dp x 315 dp) を、幅いっぱいに高さ約 200 dp の画像にスケーリングしようとすると、問題が発生します。

基本的に私がやろうとしているのは、画像がより長方形にスケーリングされたときに、画像の縦横比を適切に維持することです。何か案は?これが私が試したことです:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center" >

    <ImageView
        android:id="@+id/image"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:adjustViewBounds="true"
        android:scaleType="centerCrop" />

</LinearLayout>
4

1 に答える 1

0
It should be like that
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center" >
    <FrameLayout  
        android:layout_width="match_parent"
        android:layout_height="200dp">
    <ImageView
        android:id="@+id/image"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:adjustViewBounds="true"
        android:scaleType="fitXY" />
    </FrameLayout>

</LinearLayout>

FrameLayout は、画像のサイズを修正するものです。さらにヘルプが必要な場合は、Android UI マニュアルをお読みください。

于 2012-12-23T08:46:09.307 に答える