Android 开发笔记___图像视图

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:andro
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ImageView
        android:
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:layout_marginTop="10dp"
        android:src="@drawable/apple1" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:orientation="horizontal">

        <Button
            android:
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="fitCenter"
            android:textColor="#000000"
            android:textSize="11sp" />

        <Button
            android:
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="centerCrop"
            android:textColor="#000000"
            android:textSize="11sp" />

        <Button
            android:
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="centerInside"
            android:textColor="#000000"
            android:textSize="11sp" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:orientation="horizontal">

        <Button
            android:
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="center"
            android:textColor="#000000"
            android:textSize="11sp" />

        <Button
            android:
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="fitXY"
            android:textColor="#000000"
            android:textSize="11sp" />

        <Button
            android:
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="fitStart"
            android:textColor="#000000"
            android:textSize="11sp" />

        <Button
            android:
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="fitEnd"
            android:textColor="#000000"
            android:textSize="11sp" />

    </LinearLayout>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="截屏"
        android:/>

</LinearLayout>

  Java

package com.example.alimjan.hello_world;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

/**
 * Created by alimjan on 6/30/2017.
 */

public class class__2_3_3 extends AppCompatActivity implements View.OnClickListener {
    private ImageView iv_scale;
    private Button btn_2_3_3_2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.code_2_3_3);
        iv_scale = (ImageView) findViewById(R.id.iv_scale);
        findViewById(R.id.btn_center).setOnClickListener(this);
        findViewById(R.id.btn_fitCenter).setOnClickListener(this);
        findViewById(R.id.btn_centerCrop).setOnClickListener(this);
        findViewById(R.id.btn_centerInside).setOnClickListener(this);
        findViewById(R.id.btn_fitXY).setOnClickListener(this);
        findViewById(R.id.btn_fitStart).setOnClickListener(this);
        findViewById(R.id.btn_fitEnd).setOnClickListener(this);
        btn_2_3_3_2 = (Button) findViewById(R.id.btn_2_3_3_2);
        btn_2_3_3_2.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.btn_center) {
            iv_scale.setScaleType(ImageView.ScaleType.CENTER);
        } else if (v.getId() == R.id.btn_fitCenter) {
            iv_scale.setScaleType(ImageView.ScaleType.FIT_CENTER);
        } else if (v.getId() == R.id.btn_centerCrop) {
            iv_scale.setScaleType(ImageView.ScaleType.CENTER_CROP);
        } else if (v.getId() == R.id.btn_centerInside) {
            iv_scale.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        } else if (v.getId() == R.id.btn_fitXY) {
            iv_scale.setScaleType(ImageView.ScaleType.FIT_XY);
        } else if (v.getId() == R.id.btn_fitStart) {
            iv_scale.setScaleType(ImageView.ScaleType.FIT_START);
        } else if (v.getId() == R.id.btn_fitEnd) {
            iv_scale.setScaleType(ImageView.ScaleType.FIT_END);
        } else if (v.getId() == R.id.btn_2_3_3_2){
            class__2_3_3_2.startHome(class__2_3_3.this);
        }
    }

    public static void startHome(Context mContext) {
        Intent intent = new Intent(mContext, class__2_3_3.class);
        mContext.startActivity(intent);
    }

}