例如,如果在xml中设置了两个维度,则其行为与预期相同
android:layout_width="250dp"
android:layout_height="250dp"
Run Code Online (Sandbox Code Playgroud)
如果留给wrap_content,则不会.
这是我的布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/board"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/board" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
为什么我在屏幕上看到的图像具有正确的尺寸(屏幕高度x屏幕高度,因为它是方形位图,我设置match_parent为高度),但是如果我调用ImageView.getWidth()和ImageView.getHeight()它给了我屏幕尺寸?
最好的祝福
发生这种情况是因为我在您之前的问题中提供的原因 /sf/answers/712865961/
当你调用getWidth()和getHeight()时,它返回你的ImageView的大小,如果你观察到它是全屏大小.您的源图像已缩小以适应保持其宽高比的屏幕,但ImageView不会缩小.要将其缩小到图像大小,您需要提供参数
机器人:adjustViewBounds = "真"
在你的ImageView中.
| 归档时间: |
|
| 查看次数: |
2457 次 |
| 最近记录: |