小编Axe*_*man的帖子

在 Android 中测量“fitCenter”imageView 的边距

给定一个简单的RelativeLayout,如下所示:

    <RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#0fffff">
    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:adjustViewBounds="true"
        android:scaleType="fitCenter"
        android:src="@drawable/img001" />
    </RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

布局边框和图像边框之间的左/上间距取决于在 imageView 中加载的图像的宽/高比。

在此处输入图片说明

在此布局中显示图像后,我如何(以编程方式)知道实际边距(青色区域的宽度和高度)?

android margins imageview android-layout

2
推荐指数
1
解决办法
908
查看次数

标签 统计

android ×1

android-layout ×1

imageview ×1

margins ×1