首页 > 其他分享 >AndroidStudio学习记录(5):图像按钮ImageView的实现

AndroidStudio学习记录(5):图像按钮ImageView的实现

时间:2024-04-08 20:58:59浏览次数:14  
标签:findViewById import AndroidStudio RadioButton rb 按钮 ImageView id

<?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 图片控件;Drawable对象或bitmap对象
        src:路径图片
        maxHeight/maxWidth
        scaleType:调整尺寸-->
    <androidx.constraintlayout.utils.widget.ImageFilterView
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:src="@mipmap/ic_launcher_round"
        android:id="@+id/myImg"/>
    <RadioGroup
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/rg_scale">
        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/rb_center"
            android:text="Center"/>
        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/rb_centerCrop"
            android:text="centerCrop"/>
        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/rb_centerInside"
            android:text="centerInside"/>
        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/rb_fitEnd"
            android:text="fitEnd"/>
        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/rb_fitStart"
            android:text="fitStart"/>


    </RadioGroup>
</LinearLayout>
package com.aaa.proimg2;

import android.os.Bundle;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {

    //赋值
    ImageView myImg = (ImageView) findViewById(R.id.myImg);
    RadioGroup rg_scale = (RadioGroup) findViewById(R.id.rg_scale);
    RadioButton rb_center=(RadioButton) findViewById(R.id.rb_center);
    RadioButton rb_centerCrop=(RadioButton) findViewById(R.id.rb_centerCrop);
    RadioButton rb_centerInside=(RadioButton) findViewById(R.id.rb_centerInside);
    RadioButton rb_fitEnd=(RadioButton) findViewById(R.id.rb_fitEnd);
    RadioButton rb_fitStart=(RadioButton) findViewById( R.id.rb_fitStart);

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

        //针对单选按钮做测试:此处没有写完
        rg_scale.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int i) {
            switch (i){
                case R.id.rb_center:
                    myImg.setScaleType(ImageView.ScaleType.CENTER);break;

                case R.id.rb_centerCrop:
                    myImg.setScaleType(ImageView.ScaleType.CENTER_CROP);break;

                case  R.id.rb_centerInside:
                    myImg.setScaleType(ImageView.ScaleType.CENTER_INSIDE);break;

                case  R.id.rb_fitEnd:
                    myImg.setScaleType(ImageView.ScaleType.FIT_END);break;

                case  R.id.rb_fitStart:
                    myImg.setScaleType(ImageView.ScaleType.FIT_START);break;
                }
            }

        });
    }
}

标签:findViewById,import,AndroidStudio,RadioButton,rb,按钮,ImageView,id
From: https://blog.csdn.net/weixin_53406338/article/details/137523544

相关文章

  • 点击按钮框来选择相应信息(Vue + Java)
    目录前言1.前端2.后端3.总结前言从Java转全栈,对于项目中的功能,从无到有,都会以笔记的形式记录,方便自身的总结以及翻阅原先的知识点参考:java框架零基础从入门到精通的学习路线附开源项目面经等(超全)前后端实现下拉框带条件查询(Vue+Java)通过点击按钮框给予数据选......
  • 加价按钮 (当前价基于起拍价变化)
    效果: <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,initial-scale=1.0"><title>价格增加示例<......
  • 小米黑鲨helo手机安装应用时没有安装按钮
    情况说明:如图问题的关键点:打包apk的作者放置的图片太大了解决办法:下载ApktoolM快速编辑所要安装的apk文件更换为更小的图片......
  • AndroidStudio学习记录(4):单选按钮控件RadioButton
    用于应用二选一等多选选项的设置<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical">&l......
  • AndroidStudio学习记录(3):操纵按钮控件Botton、ImageBotton
    按钮控件是平时看到的,常用Botton和ImageButton控件,一般操纵按钮来实现相应的命令,比如在手机上的查找登录注册,以及点击命令等等。ImaBotton与Button的区别在于它没有文本,只有图片,需要制定图片路径在activity_main.xml文件中,它们是这样使用的:<?xmlversion="1.0"encoding=......
  • vue表单点击按钮增加或者删除一行
    vue表单点击按钮增加或者删除一行不需要动态改变的就不用放在一个form-item中,可以单独写一个form-item。需要点击增加和删除的表单项目可以用v-for来循环渲染。<a-form:label-col="{span:8}":wrapper-col="{span:12}"> <a-form-itemlabel="服务器名称">......
  • PyQt:【重磅干货】实现一个自定义样式的窗口(比如去掉边框、改变标题位置、窗口按钮样式
    如果想突破PyQt自带窗口的样式限制,比如同时去掉窗口的边框、改变边框、改变标题位置、窗口控制按钮等等,那就需要实现一个自定义样式的窗口,本文教你如何实现先来看看PyQt创建窗口的默认样式:再看看一个自定义样式的窗口:可以看到,这里示例的自定义窗口去掉了窗口的边框、改......
  • vue3 点击按钮跳转到对应的tab页面
     大家好呀,我又来记录一下啦实现功能:点击”查看“按钮,跳转到对应的tab页面方法:router按钮部分:<el-buttonsize="small"@click="check(scope.row.name)">查看</el-button>对应的方法:check(){this.$router.push({path:'/about'})},router:import......
  • 前端学习-UI框架学习-Bootstrap5-010-按钮组
    菜鸟教程链接btn-group按钮组<template><divclass="containermt-3"><h2>加载按钮组</h2><divclass="btn-group"><buttonclass="btnbtn-primary">......
  • 前端学习-UI框架学习-Bootstrap5-009-按钮
    菜鸟教程链接按钮按钮类可用于,,或元素上:<template><divclass="containermt-3"><h2>按钮元素</h2><ahref="#"class="btnbtn-infom-3"role="button">链接按钮</a><buttontype="......