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 @ 2017-08-31 11:46  QiaoZhi  阅读(418)  评论(0编辑  收藏  举报