0

我有以下小部件:

小部件差异大小

如果小部件大小 w=h ,则图像可以,但如果不同,则其拉伸。

如何保持比例?调整大小甚至应该可以工作。

我的 XML:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/Widget"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >

<ImageView
    android:id="@+id/buttonwidget"
    android:src="@drawable/normalwidget"
    android:layout_gravity="center"
    android:adjustViewBounds="true"
    android:fitsSystemWindows="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="fitXY" >
</ImageView>

如果可能的话,我更喜欢 XML 解决方案而不是 Drawable 代码。

4

1 回答 1

2

感谢@Samuil Yanovski,他确实修复了它..

我将我的 XML 更改为:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/Widget"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >

<ImageView
    android:id="@+id/buttonwidget"
    android:src="@drawable/normalwidget"
    android:layout_gravity="center"
    android:adjustViewBounds="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="fitCenter">
</ImageView>

</FrameLayout>

一切都很好,我喜欢它:)

全部固定

于 2013-09-08T18:14:09.903 回答