Android控件——ImageView

 

   android:orientation="vertical"  修改布局文件垂直排列

  

放置图片:

  1.通过src引入图片;

  2.通过background引入背景图片

  3.bacoground引入背景颜色块

1.xml

复制代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <!-- src与background共存 -->
    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#f0f0f0"
        android:src="@drawable/ic_launcher" />

    <!-- background背景图片 -->
    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/ic_launcher" />

    <!-- background背景颜色 -->
    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="#000000" />

</LinearLayout>
复制代码

 

2.Java代码:

3.效果:

 

------------------------------不同分辨率的图片处理情况------------------------

当我们写了ImageView的时候,在手机上运行的时候底层会判断当前手机是高分辨率还是低分辨率,然后去对应的drawable下面选择对应分辨率的图片。

测试:在不同分辨率的文件夹下放置名字相同,内容不同的图片。

 

1.准备图片:

 

drawable-hdpi文件夹下的图片:

  

 

drawable-xhdpi文件夹下的图片:

  

drawable-xxhdpi文件夹的图片:

  

2.修改xml布局文件

    <!-- src与background共存 -->
    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#f0f0f0"
        android:src="@drawable/img1" />

 

 

3.点击查看图片

 

(1)选择分辨率为hdpi

 

 

(2)选择分辨率为xhdpi

 

 

posted @   QiaoZhi  阅读(421)  评论(0编辑  收藏  举报
编辑推荐:
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· Obsidian + DeepSeek:免费 AI 助力你的知识管理,让你的笔记飞起来!
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示