亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

Android圖像視圖ImageView實現圖像拉伸效果

瀏覽:5日期:2022-09-18 15:10:34

本文實例為大家分享了Android圖像視圖ImageView實現圖像拉伸效果的具體代碼,供大家參考,具體內容如下

在layout調整屬性src指定圖形來源。Activity中setScaleType設置圖形的拉伸類型。

MainActivity

package com.example.junior; import android.os.Bundle;import androidx.appcompat.app.AppCompatActivity;import android.view.View;import android.widget.ImageView; // 頁面類直接實現點擊監聽器的接口View.OnClickListenerpublic class ScaleActivity extends AppCompatActivity implements View.OnClickListener { private ImageView iv_scale; // 聲明一個圖像視圖的對象 @Override protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_scale);// 從布局文件中獲取名叫iv_scale的圖像視圖iv_scale = 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); } @Override public void onClick(View v) { // 一旦監聽到點擊動作,就觸發監聽器的onClick方法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);} }}

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'> <ImageViewandroid: android:layout_width='match_parent'android:layout_height='200dp'android:layout_marginTop='10dp'android:src='http://www.aoyou183.cn/bcjs/@drawable/apple1' /> <LinearLayoutandroid: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> <LinearLayoutandroid: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> </LinearLayout>

result

Android圖像視圖ImageView實現圖像拉伸效果

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Android
相關文章:
主站蜘蛛池模板: 99久久精品国产免看国产一区 | 亚洲一区二区观看 | 亚洲一区欧洲一区 | 黄色一级片视频 | 久久精品网站免费观看 | 国产成人深夜福利短视频99 | 色婷婷综合久久久 | 黄色在线观看免费 | pans国产大尺度私密拍摄视频 | 欧美精品v日韩精品v国产精品 | 国产日产欧产精品精品推荐在线 | 美国一级大黄一片免费网站 | 福利二区 | 国产精品一二区 | 欧洲a级毛片 | 亚洲欧美一区二区三区在饯 | 国产成人盗拍精品免费视频 | 久久久免费精品 | 国产一级做a爰片久久毛片99 | 国产精品视频一区日韩丝袜 | 毛片网在线 | 狠狠色欧美亚洲狠狠色五 | 国产精品成人69xxx免费视频 | 国产精品va在线观看手机版 | 国产激情自拍视频 | 在线观看国产日韩 | 免费在线一级片 | 久久青草网站 | 国产制服丝袜视频 | 日韩综合第一页 | 最新lutube亚洲看片在线观看 | 国产亚洲精品激情一区二区三区 | 日韩最新中文字幕 | 国产二区三区毛片 | 欧美色图中文字幕 | 成人国产视频在线观看 | 97精品国产自在现线免费 | 国产大片黄在线看免费 | 中国人xxxxxxx免费看 | 精品国产欧美一区二区三区成人 | 欧美三片 |