最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android圖像視圖ImageView實(shí)現(xiàn)圖像拉伸效果

 更新時(shí)間:2021年05月21日 10:56:11   作者:打代碼的浪浪  
這篇文章主要為大家詳細(xì)介紹了Android圖像視圖ImageView實(shí)現(xiàn)圖像拉伸演示,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android圖像視圖ImageView實(shí)現(xiàn)圖像拉伸效果的具體代碼,供大家參考,具體內(nèi)容如下

在layout調(diào)整屬性src指定圖形來(lái)源。Activity中setScaleType設(shè)置圖形的拉伸類(lèi)型。

MainActivity

package com.example.junior;
 
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
 
// 頁(yè)面類(lèi)直接實(shí)現(xiàn)點(diǎn)擊監(jiān)聽(tīng)器的接口View.OnClickListener
public class ScaleActivity extends AppCompatActivity implements View.OnClickListener {
    private ImageView iv_scale; // 聲明一個(gè)圖像視圖的對(duì)象
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scale);
        // 從布局文件中獲取名叫iv_scale的圖像視圖
        iv_scale = findViewById(R.id.iv_scale);
        // 下面通過(guò)七個(gè)按鈕,分別演示不同拉伸類(lèi)型的圖片拉伸效果
        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);
    }
 
    @Override
    public void onClick(View v) {  // 一旦監(jiān)聽(tīng)到點(diǎn)擊動(dòng)作,就觸發(fā)監(jiān)聽(tīng)器的onClick方法
        if (v.getId() == R.id.btn_center) {
            // 將拉伸類(lèi)型設(shè)置為“按照原尺寸居中顯示”
            iv_scale.setScaleType(ImageView.ScaleType.CENTER);
        } else if (v.getId() == R.id.btn_fitCenter) {
            // 將拉伸類(lèi)型設(shè)置為“保持寬高比例,拉伸圖片使其位于視圖中間”
            iv_scale.setScaleType(ImageView.ScaleType.FIT_CENTER);
        } else if (v.getId() == R.id.btn_centerCrop) {
            // 將拉伸類(lèi)型設(shè)置為“拉伸圖片使其充滿(mǎn)視圖,并位于視圖中間”
            iv_scale.setScaleType(ImageView.ScaleType.CENTER_CROP);
        } else if (v.getId() == R.id.btn_centerInside) {
            // 將拉伸類(lèi)型設(shè)置為“保持寬高比例,縮小圖片使之位于視圖中間(只縮小不放大)”
            iv_scale.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        } else if (v.getId() == R.id.btn_fitXY) {
            // 將拉伸類(lèi)型設(shè)置為“拉伸圖片使其正好填滿(mǎn)視圖(圖片可能被拉伸變形)”
            iv_scale.setScaleType(ImageView.ScaleType.FIT_XY);
        } else if (v.getId() == R.id.btn_fitStart) {
            // 將拉伸類(lèi)型設(shè)置為“保持寬高比例,拉伸圖片使其位于視圖上方或左側(cè)”
            iv_scale.setScaleType(ImageView.ScaleType.FIT_START);
        } else if (v.getId() == R.id.btn_fitEnd) {
            // 將拉伸類(lèi)型設(shè)置為“保持寬高比例,拉伸圖片使其位于視圖下方或右側(cè)”
            iv_scale.setScaleType(ImageView.ScaleType.FIT_END);
        }
    }
}

layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
 
    <ImageView
        android:id="@+id/iv_scale"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        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:id="@+id/btn_fitCenter"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="fitCenter"
            android:textColor="#000000"
            android:textSize="11sp" />
 
        <Button
            android:id="@+id/btn_centerCrop"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="centerCrop"
            android:textColor="#000000"
            android:textSize="11sp" />
 
        <Button
            android:id="@+id/btn_centerInside"
            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:id="@+id/btn_center"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="center"
            android:textColor="#000000"
            android:textSize="11sp" />
 
        <Button
            android:id="@+id/btn_fitXY"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="fitXY"
            android:textColor="#000000"
            android:textSize="11sp" />
 
        <Button
            android:id="@+id/btn_fitStart"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="fitStart"
            android:textColor="#000000"
            android:textSize="11sp" />
 
        <Button
            android:id="@+id/btn_fitEnd"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="fitEnd"
            android:textColor="#000000"
            android:textSize="11sp" />
 
    </LinearLayout>
 
</LinearLayout>

result

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android通過(guò)startService實(shí)現(xiàn)文件批量下載

    Android通過(guò)startService實(shí)現(xiàn)文件批量下載

    這篇文章主要為大家詳細(xì)介紹了Android通過(guò)startService實(shí)現(xiàn)文件批量下載的示例,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2015-12-12
  • Android實(shí)現(xiàn)指針刻度轉(zhuǎn)盤(pán)

    Android實(shí)現(xiàn)指針刻度轉(zhuǎn)盤(pán)

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)指針刻度轉(zhuǎn)盤(pán),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-08-08
  • Android實(shí)現(xiàn)頭像上傳功能

    Android實(shí)現(xiàn)頭像上傳功能

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)頭像上傳功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-12-12
  • [Android] 通過(guò)GridView仿微信動(dòng)態(tài)添加本地圖片示例代碼

    [Android] 通過(guò)GridView仿微信動(dòng)態(tài)添加本地圖片示例代碼

    本篇文章主要介紹了[Android] 通過(guò)GridView仿微信動(dòng)態(tài)添加本地圖片示例代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。
    2017-01-01
  • Android應(yīng)用開(kāi)發(fā)中使用Fragment的入門(mén)學(xué)習(xí)教程

    Android應(yīng)用開(kāi)發(fā)中使用Fragment的入門(mén)學(xué)習(xí)教程

    這篇文章主要介紹了Android應(yīng)用開(kāi)發(fā)中Fragment的入門(mén)學(xué)習(xí)教程,可以把Fragment看作為Activity基礎(chǔ)之上的模塊,需要的朋友可以參考下
    2016-02-02
  • Android列表動(dòng)圖展示的實(shí)現(xiàn)策略

    Android列表動(dòng)圖展示的實(shí)現(xiàn)策略

    這篇文章主要給大家介紹了關(guān)于Android列表動(dòng)圖展示的實(shí)現(xiàn)策略的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2018-11-11
  • Android 實(shí)現(xiàn)右滑返回功能

    Android 實(shí)現(xiàn)右滑返回功能

    右滑返回功能在ios上非常實(shí)用,因?yàn)樗姆祷劓I在左上角,下面腳本之家小編給大家?guī)?lái)了Android 實(shí)現(xiàn)右滑返回功能,感興趣的朋友一起看看吧
    2018-04-04
  • Android開(kāi)發(fā)在RecyclerView上面實(shí)現(xiàn)

    Android開(kāi)發(fā)在RecyclerView上面實(shí)現(xiàn)"拖放"和"滑動(dòng)刪除"-2

    這篇文章主要介紹了Android開(kāi)發(fā)在RecyclerView上面實(shí)現(xiàn)"拖放"和"滑動(dòng)刪除"(二)功能,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2017-03-03
  • 擁抱kotlin之如何習(xí)慣使用kotlin高階函數(shù)

    擁抱kotlin之如何習(xí)慣使用kotlin高階函數(shù)

    這篇文章主要給大家介紹了關(guān)于擁抱kotlin之如何習(xí)慣使用kotlin高階函數(shù)的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用kotlin具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-12-12
  • Flutter?list?數(shù)組排序示例解析

    Flutter?list?數(shù)組排序示例解析

    這篇文章主要為大家介紹了Flutter?list?數(shù)組排序?qū)崿F(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-05-05

最新評(píng)論

中宁县| 双辽市| 东明县| 富平县| 海淀区| 阜阳市| 平和县| 长宁区| 平度市| 饶平县| 徐闻县| 焦作市| 瑞安市| 呼和浩特市| 革吉县| 长白| 噶尔县| 黎平县| 嘉鱼县| 丽水市| 仙居县| 山阴县| 沁水县| 汉中市| 邓州市| 临沂市| 永济市| 巴青县| 文登市| 星座| 台山市| 磐石市| 犍为县| 多伦县| 廉江市| 商都县| 仙桃市| 扎赉特旗| 梁平县| 东光县| 荥阳市|