Android Studio 图片控件ImageView

柔光的暖阳◎ 2023-07-19 08:14 131阅读 0赞

点此查看全部文字教程、视频教程、源代码

本文目录

    1. 功能
    1. 显示图片实例

1. 功能

ImageView用来显示图片,比较重要的属性有:

  • src,指定图片来源
  • scaleType,图片的拉伸类型,例如填满视图等。

2. 显示图片实例

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="vertical"
  6. android:padding="4dp">
  7. <ImageView
  8. android:layout_width="match_parent"
  9. android:layout_height="wrap_content"
  10. android:src="@mipmap/ic_launcher"
  11. android:scaleType="center"/>
  12. <ImageView
  13. android:layout_width="match_parent"
  14. android:layout_height="wrap_content"
  15. android:src="@mipmap/ic_launcher"
  16. android:scaleType="centerCrop"/>
  17. <ImageView
  18. android:layout_width="match_parent"
  19. android:layout_height="wrap_content"
  20. android:src="@mipmap/ic_launcher"
  21. android:scaleType="centerInside"/>
  22. <ImageView
  23. android:layout_width="match_parent"
  24. android:layout_height="wrap_content"
  25. android:src="@mipmap/ic_launcher"
  26. android:scaleType="fitXY"/>
  27. <ImageView
  28. android:layout_width="match_parent"
  29. android:layout_height="wrap_content"
  30. android:src="@mipmap/ic_launcher"
  31. android:scaleType="fitStart"/>
  32. <ImageView
  33. android:layout_width="match_parent"
  34. android:layout_height="wrap_content"
  35. android:src="@mipmap/ic_launcher"
  36. android:scaleType="fitEnd"/>
  37. <ImageView
  38. android:layout_width="match_parent"
  39. android:layout_height="wrap_content"
  40. android:src="@mipmap/ic_launcher"
  41. android:scaleType="fitCenter"/>
  42. </LinearLayout>

效果:
在这里插入图片描述

发表评论

表情:
评论列表 (有 0 条评论,131人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Android studio的详细用法

    Android Studio控件的详细用法取决于您想要实现的功能。一般来说,每个控件都有一组属性、方法和事件,可以使用这些属性、方法和事件来控制控件的外观和行为。您可以查阅An