安卓基本控件之ImageView

布局文件

<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="horizontal" >

    <!-- 第一列 -->

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical"
         >
        <!--默认显示的图片  -->
        <ImageView
            android:layout_width="100dp"
            android:layout_height="150dp"
            android:src="@drawable/test_small" />
        <!-- android:scaleType="matrix" 保持图片的原比例 如果图片大 从左上角截取ImageView宽高的图片 -->
        <ImageView
            android:layout_width="100dp"
            android:layout_height="150dp"
            android:src="@drawable/test_small"
            android:scaleType="matrix"
            />
        <!--    android:scaleType="fitXY" 不按图片比例进行缩放  直至完全填充ImageView -->
        <ImageView
            android:layout_width="100dp"
            android:layout_height="150dp"
            android:src="@drawable/test_small"
            android:scaleType="fitXY"
            />
    </LinearLayout>
    <!-- 第二列 -->

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical"
        >
        
        <!-- android:scaleType="fitStart" 按图片比例进行缩放 显示在ImageView的顶部   -->
        <ImageView
            android:layout_width="100dp"
            android:layout_height="150dp"
            android:src="@drawable/test_small"
            android:scaleType="fitStart"
            />
        <!-- android:scaleType="fitCenter" 按图片比例进行缩放 显示在ImageView的中央   -->
        <ImageView
            android:layout_width="100dp"
            android:layout_height="150dp"
            android:src="@drawable/test_small"
            android:scaleType="fitCenter"
            />
        <!-- android:scaleType="fitEnd" 按图片比例进行缩放 显示在ImageView的底部   -->
        <ImageView
            android:layout_width="100dp"
            android:layout_height="150dp"
            android:src="@drawable/test_small"
            android:scaleType="fitEnd"
            />
    </LinearLayout>
    <!-- 第三列 -->

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical"
        >
        
        <!--   不进行缩放  从中间开始截取  截取和ImageView相同大小的图片 -->
        <ImageView
            android:layout_width="100dp"
            android:layout_height="150dp"
            android:src="@drawable/test_small"
            android:scaleType="center"
            />
        <!--   等比例进行缩放   从中间位置 开始截取和ImageView相同大小的图片-->
        <ImageView
            android:layout_width="100dp"
            android:layout_height="150dp"
            android:src="@drawable/test_small"
            android:scaleType="centerCrop"
            />
        <!--   等比例缩小图片  显示在ImageView 中间部分-->
        <ImageView
            android:layout_width="100dp"
            android:layout_height="150dp"
            android:src="@drawable/test_small"
            android:scaleType="centerInside"
            />
    </LinearLayout>

</LinearLayout>

Java代码


import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值