Android——基本控件下(十七)

news2024/9/30 15:22:31

1. 文本切换:TextSwitcher

1.1 知识点

(1)理解TextSwitcher和ViewFactory的使用。

1.2 具体内容

 范例:切换显示当前时间

<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="vertical" >
    <TextSwitcher
        android:id="@+id/myTextSwitcher"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:layout_gravity="center_horizontal"/>
    <Button
        android:id="@+id/but"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:text="显示当前时间"
        android:layout_gravity="center_horizontal"/>

</LinearLayout>
package com.example.textswitcher;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.ViewSwitcher.ViewFactory;

public class TextSwitcherActivity extends Activity {
	private Button but = null;
	private TextSwitcher textSwitcher = null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		super.setContentView(R.layout.activity_text_switcher);
		this.but = (Button) super.findViewById(R.id.but);
		this.textSwitcher = (TextSwitcher) super.findViewById(R.id.myTextSwitcher);
		this.textSwitcher.setFactory(new ViewFactory() {
			@Override
			public View makeView() {
				TextView textView = new TextView(TextSwitcherActivity.this);
				textView.setLayoutParams(new TextSwitcher.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
				textView.setBackgroundColor(0xFFFFFFFF);
				textView.setTextSize(30);
				return textView;
			}
		});
		this.but.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v) {
				Date date = new Date();
				DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
				String sDate = df.format(date);//将Date类型的日期转换成字符串
				TextSwitcherActivity.this.textSwitcher.setText("当前时间:"+sDate);
			}
			
		});
	}
}

当然也可以设置动画效果。

<TextSwitcher
        android:id="@+id/myTextSwitcher"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:layout_gravity="center_horizontal"
        android:inAnimation="@android:anim/slide_in_left"
        android:outAnimation="@android:anim/slide_out_right"/>

1.3 小结

(1)TextSwitcher与ImageSwitcher一样,如果需要转换都必须通过ViewFactory接口设置。

2. 拖拉图片:Gallery

2.1 知识点

(1)掌握Gallery组件的使用;

(2)使用Gallery + ImageSwitcher完成图片浏览功能。

2.2 具体内容

 

 

我们通过API去查找SpinnerAdapter这个接口。发现此接口有几个实现类:ArrayAdapter,SimpleAdapter,BaseAdapter 

  ·使用ArrayAdapter,BaseAdapter实际上就是需要开发者自己去实现Adapter的操作,包括定义组件等。

第一步:编写自定义适配器

package com.example.galleryproject;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;

public class ImageGalleryAdapter extends BaseAdapter{
	private Context context;
	private int img[] = {R.drawable.head0,R.drawable.head1,R.drawable.head2,
			R.drawable.head3,R.drawable.head4,R.drawable.head5,
			R.drawable.head6,R.drawable.head7,R.drawable.head8,
			R.drawable.head9,R.drawable.head10,R.drawable.head11,};
	public ImageGalleryAdapter(Context context){
		this.context = context;
	}
	@Override
	public int getCount() {//返回图片个数
		return img.length;
	}
	@Override
	public Object getItem(int position) {//取得指定位置的图片
		return img[position];
	}
	@Override
	public long getItemId(int position) {//取得指定位置的图片ID
		return img[position];
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		//很明显,现在我们是要浏览图片,那么图片肯定是需要使用ImageView
		ImageView imgView = new ImageView(context);
		imgView.setBackgroundColor(0xFFFFFFFF);
		imgView.setImageResource(this.img[position]);
		imgView.setScaleType(ImageView.ScaleType.CENTER);//设置居中显示
		imgView.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
		return imgView;
	}
}

 

此时自定义的适配器就已经完成,是一个专门负责给Gallery组件填充数据的适配器,当Gallery需要显示内容的时候,直接是用setAdapter()方法设置这个自定义的适配器就OK了。

第二步:定义布局文件

<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="vertical" >
    <Grallery
        android:id="@+id/myGallery"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
		android:layout_gravity="center_horizontal"
		/>
</LinearLayout>

 定义了布局文件之后,我们需要编写Activity程序。

package com.example.galleryproject;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Gallery;
import android.widget.Toast;

public class GalleryActivity extends Activity {
	private Gallery myGallery = null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		super.setContentView(R.layout.activity_gallery);
		this.myGallery = (Gallery) super.findViewById(R.id.myGallery);
		this.myGallery.setAdapter(new ImageGalleryAdapter(this));
		this.myGallery.setOnItemClickListener(new OnItemClickListener(){

			@Override
			public void onItemClick(AdapterView<?> adapter, View view, int position,
					long id) {
				Toast.makeText(GalleryActivity.this, "选中了第"+(position+1)+"张图片", Toast.LENGTH_SHORT).show();
			}
			
		});
	}
}

 

从事件处理来看,和ListView组件操作相似的。

·对于使用SimpleAdapter来说,必须要准备一个List,而这个List里面保存的是Map,而且Map中的key值要是字符串类型,如果现在有100个图片需要使用画廊组件现,这个时候我们可以做一些特殊的处理。

第一步:准备一张图片的显示的模板布局

 

<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" >
    <ImageView
        android:id="@+id/mtImg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="center"
		/>
</LinearLayout>

第二部:编写Activity程序,实现画廊

package com.example.galleryproject;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Gallery;
import android.widget.SimpleAdapter;
import android.widget.Toast;

public class GalleryActivity extends Activity {
	private Gallery myGallery = null;
	private SimpleAdapter adapter = null;
	private List<Map<String,Integer>> list = new ArrayList<Map<String,Integer>>();
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		super.setContentView(R.layout.activity_gallery);
		this.myGallery = (Gallery) super.findViewById(R.id.myGallery);
		this.initAdapter();//装配适配器
		this.myGallery.setAdapter(adapter);
		this.myGallery.setOnItemClickListener(new OnItemClickListener(){
			@Override
			public void onItemClick(AdapterView<?> adapter, View view, int position,
					long id) {
				Toast.makeText(GalleryActivity.this, "选中了第"+(position+1)+"张图片", Toast.LENGTH_SHORT).show();
			}
		});
	}
	/**
	 * 装配适配器
	 */
	public void initAdapter(){
		//我们说如果有非常多的图片,一个一个列出来非常麻烦 现在使用一些IO知识,通过图片名称的前半部分相同就全部加载进来
		Field field[] = R.drawable.class.getDeclaredFields();//取得drawable全部内容
		for (int i = 0; i < field.length; i++) {
			if(field[i].getName().startsWith("head")){
				Map<String,Integer> map = new HashMap<String,Integer>();
				try{
					map.put("img",field[i].getInt(R.drawable.class));
				}catch(Exception e){
					e.printStackTrace();
				}
				this.list.add(map);
			}
		}
		this.adapter = new SimpleAdapter(this,this.list,R.layout.gallery_view,new String[]{"img"},new int[]{R.id.myImg});
	}
}

以上的操作都是实现了简单的画廊,在很多情况下,用户可以通过选择一张图片,然后直接显示这个图片在中央,这就是说进行了图片的切换,那么需要依靠ImageSwitcher完成。

<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="vertical" >
    <ImageSwitcher
        android:id="@+id/myImageSwitcher"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />
    <Gallery
        android:id="@+id/myGallery"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
		android:layout_gravity="center_horizontal"
		android:spacing="3px"
		/>
</LinearLayout>
package com.example.galleryproject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Gallery;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.SimpleAdapter;
import android.widget.ViewSwitcher.ViewFactory;

public class GalleryActivity extends Activity {
	private Gallery myGallery = null;
	private SimpleAdapter adapter = null;
	private List<Map<String, Integer>> list = new ArrayList<Map<String, Integer>>();
	private ImageSwitcher imageSwitcher = null;
	private int img[] = { R.drawable.head0, R.drawable.head1, R.drawable.head2,
			R.drawable.head3, R.drawable.head4, R.drawable.head5,
			R.drawable.head6, R.drawable.head7, R.drawable.head8,
			R.drawable.head9, R.drawable.head10, R.drawable.head11, };

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		super.setContentView(R.layout.activity_gallery);
		this.myGallery = (Gallery) super.findViewById(R.id.myGallery);
		this.imageSwitcher = (ImageSwitcher) super.findViewById(R.id.myImageSwitcher);
		this.imageSwitcher.setFactory(new ViewFactory() {
			@Override
			public View makeView() {
				ImageView imgView = new ImageView(GalleryActivity.this);
				imgView.setBackgroundColor(0xFFFFFFFF);
				imgView.setScaleType(ImageView.ScaleType.CENTER);//设置居中显示
				imgView.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
				return imgView;
			}
		});
		this.imageSwitcher.setImageResource(img[0]);
		this.initAdapter();//装配适配器
		this.myGallery.setAdapter(adapter);
		this.myGallery.setOnItemClickListener(new OnItemClickListener(){
			@Override
			public void onItemClick(AdapterView<?> adapter, View view, int position,
					long id) {
				GalleryActivity.this.imageSwitcher.setImageResource(img[position]);
			}
		});
	}
	/**
	 * 装配适配器
	 */
	public void initAdapter() {
		for (int i = 0; i < img.length; i++) {
			Map<String, Integer> map = new HashMap<String, Integer>();
			try {
				map.put("img", img[i]);
			} catch (Exception e) {
				e.printStackTrace();
			}
			this.list.add(map);
		}
		this.adapter = new SimpleAdapter(this, this.list,
				R.layout.gallery_view, new String[] { "img" },
				new int[] { R.id.myImg });
	}
}

在使用BaseAdapter的时候需要自定义一个适配器类,而是用SimpleAdapter的时候必须要定义布局模板。

2.3 小结

(1)Gallery组件可以完成图片的拖拉浏览功能;

(2)使用Gallery + ImageSwitcher组件可以完成图片的切换操作;

3. 网格视图:GridView

3.1 知识点

(1)掌握GridView的特点及应用;

(2)可以使用BaseAdapter进行GridView显示内容的设置。

3.2 具体内容

 

 

主页面的布局:

<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    tools:context=".GridViewActivity" >

    <GridView 
        android:id="@+id/myGirdView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:numColumns="3" – 每行加载多少个单元格
        android:stretchMode="columnWidth"  --设置缩放的时候保持列宽的一致
        />

</LinearLayout>

 单元格的布局:

<?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/img"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="center"
        android:padding="10px"
        />

</LinearLayout>

 Activity:

package com.example.gridviewproject;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.os.Bundle;
import android.widget.GridView;
import android.widget.SimpleAdapter;

public class GridViewActivity extends Activity {
	SimpleAdapter adapter = null;
	List<Map<String,Integer>> list = new ArrayList<Map<String,Integer>>();
    GridView gv = null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_grid_view);
		gv = (GridView) super.findViewById(R.id.myGirdView);
		this.initAdapter();
		gv.setAdapter(adapter);
	}

	
	
	public void initAdapter(){//装载adapter
		Field[] fields = R.drawable.class.getDeclaredFields();//取得所有的图片
		for(int i=0;i<fields.length;i++){
			if(fields[i].getName().startsWith("date")){
				Map<String,Integer> map = new HashMap<String,Integer>();
				try {
					map.put("img", fields[i].getInt(R.drawable.class));
				} catch (IllegalArgumentException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IllegalAccessException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				this.list.add(map);
			}
		}
		this.adapter = new SimpleAdapter(this,list,R.layout.gird_view_item,new String[]{"img"},new int[]{R.id.img});
	}
}

到这里为止,完成了网格视图的加载,那么接下来进行事件处理,单击显示图片

package com.example.gridviewproject;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SimpleAdapter;

public class GridViewActivity extends Activity {
	SimpleAdapter adapter = null;
	List<Map<String,Integer>> list = new ArrayList<Map<String,Integer>>();
    GridView gv = null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_grid_view);
		gv = (GridView) super.findViewById(R.id.myGirdView);
		this.initAdapter();
		gv.setAdapter(adapter);
		gv.setOnItemClickListener(new OnItemClickListenerImpl());
	}

	
	
	public void initAdapter(){//装载adapter
		Field[] fields = R.drawable.class.getDeclaredFields();//取得所有的图片
		for(int i=0;i<fields.length;i++){
			if(fields[i].getName().startsWith("date")){
				Map<String,Integer> map = new HashMap<String,Integer>();
				try {
					map.put("img", fields[i].getInt(R.drawable.class));
				} catch (IllegalArgumentException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IllegalAccessException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				this.list.add(map);
			}
		}
		this.adapter = new SimpleAdapter(this,list,R.layout.gird_view_item,new String[]{"img"},new int[]{R.id.img});
	}
	
	private class OnItemClickListenerImpl implements OnItemClickListener{

		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			Map<String,Integer> map = (Map<String, Integer>) GridViewActivity.this.adapter.getItem(arg2);//取得所点击的图片
			ImageView showImg = new ImageView(GridViewActivity.this);
			showImg.setScaleType(ImageView.ScaleType.CENTER);//代表设置图片居中
			showImg.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
			showImg.setImageResource(map.get("img"));
			Dialog dialog = new AlertDialog.Builder(GridViewActivity.this).setIcon(R.drawable.ic_launcher)
					         .setTitle("显示图片").setView(showImg).setNegativeButton("取消", null).create();
			dialog.show();//显示对话框
		}}
	
}

 以上使用的是SimpleAdapter完成的,现在使用BaseAdapter完成

专门定义一个新的适配器类:

package com.example.myAdapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class ImageAdapter extends BaseAdapter {
    private List<Integer> list;
	private Context context;
	
	public ImageAdapter(List<Integer> list, Context context) {
		super();
		this.list = list;
		this.context = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return this.list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return this.list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return this.list.get(position);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
        ImageView showImg = new ImageView(this.context);
        showImg.setScaleType(ImageView.ScaleType.CENTER);//
        showImg.setImageResource(list.get(position));
        showImg.setPadding(10,10,10,10);
		return showImg;
	}

}
package com.example.gridviewproject;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.example.myAdapter.ImageAdapter;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SimpleAdapter;

public class GridViewActivity extends Activity {
	List<Integer> list = new ArrayList<Integer>();
    GridView gv = null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_grid_view);
		gv = (GridView) super.findViewById(R.id.myGirdView);
		this.initAdapter();
		gv.setAdapter(new ImageAdapter(list, this));
		gv.setOnItemClickListener(new OnItemClickListenerImpl());
	}

	
	
	public void initAdapter(){//装载adapter
		Field[] fields = R.drawable.class.getDeclaredFields();//取得所有的图片
		for(int i=0;i<fields.length;i++){
			if(fields[i].getName().startsWith("date")){
              try {
				this.list.add(fields[i].getInt(R.drawable.class));
			} catch (IllegalArgumentException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}				
			}
		}
	}
	
	private class OnItemClickListenerImpl implements OnItemClickListener{

		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			ImageView showImg = new ImageView(GridViewActivity.this);
			showImg.setScaleType(ImageView.ScaleType.CENTER);//代表设置图片居中
			showImg.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
			showImg.setImageResource(list.get(arg2));
			Dialog dialog = new AlertDialog.Builder(GridViewActivity.this).setIcon(R.drawable.ic_launcher)
					         .setTitle("显示图片").setView(showImg).setNegativeButton("取消", null).create();
			dialog.show();//显示对话框
		}}
	
}

3.3 小结

(1)GridView可以进行网格的显示操作;

(2)GridView的内容可以使用SimpleAdapter设置,也可以通过自定义的BaseAdapter子类完成设置。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/920011.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【业务功能篇76】微服务网关路由predicates断言条件-filters路由转换地址-跨域问题-多级目录树化层级设计-mybatisPlus逻辑删除

业务开发-基础业务-分类管理 启动renren-fast如果出现如下错误 -Djps.track.ap.dependenciesfalse 添加相关配置即可 分类管理 1.后端分类接口 JDK8特性&#xff1a;https://blog.csdn.net/qq_38526573/category_11113126.html 在后端服务中我们需要查询出所有的三级分类信…

住宅IP:解锁更快速、稳定的互联网,你准备好了吗?

随着互联网的广泛普及&#xff0c;我们对网络的需求也越来越高。无论是工作、学习还是娱乐&#xff0c;我们都希望能够享受到更快速、稳定的互联网连接。而在实现这一目标的过程中&#xff0c;住宅IP正逐渐崭露头角&#xff0c;成为了一种备受关注的解决方案。那么&#xff0c;…

dig批量域名逆向查询ip

dig批量域名逆向查询ip dig nocmd noall answer -f iplist.txtiplist.txt中内容 效果图&#xff1a; dig其他选项参数&#xff1a; dig www.baidu.com A # 查询A记录&#xff0c;如果域名后面不加任何参数&#xff0c;默认查询A记录 dig www.baidu.com MX # 查询MX记…

利用TinyPng实现自动压图工具并管理

做游戏开发都会有缩减包体的问题&#xff0c;压图就是一个途径&#xff0c;用什么工具压图有很多工具和方法&#xff0c;我喜欢使用TinyPng&#xff0c;我自己久用python写了一个方便压图的工具。 ​​​​​​​​​​​​​​TinyPnghttps://tinypng.com/ 大家应该都用过&am…

Java学习笔记40

Java笔记40 创建运行时类的对象 获取运行时类的完整结构 我们可以通过反射来获取运行时类的完整结构&#xff0c;这包括&#xff1a; 实现的全部接口&#xff08;Interface&#xff09;所继承的父类&#xff08;Superclass&#xff09;全部的构造器&#xff08;Constructor&…

10 Mybatis

文章目录 1 概述1.1 什么是Mybatis?1.2 JDBC介绍(了解)1.2.1 问题分析1.2.2 技术对比 1.3 数据库连接池1.4 lombok 2 Mybatis基础操作2.1 准备2.2 删除2.2.1 日志输入2.2.2 预编译SQL2.2.2.1 介绍2.2.2.2 SQL注入2.2.2.3 参数占位符 2.3 新增2.3.1 主键返回 2.4 更新2.5 查询2…

Java 内置注解

一、内置注解 Java内置注解 也称 Java标准注解&#xff0c;是Java JDK 中自带的注解。Java 中有许多标准注解&#xff0c;以下是一些常见的标准注解&#xff1a; 1. Override&#xff1a;用于表示一个方法是重写父类中的方法。 2. Deprecated&#xff1a;用于标记已经过时的方法…

vue 使用print.js打印小票

官网&#xff1a;https://printjs.crabbly.com/ // 安装 npm install print-js --save// 引入 import printJS from print-js// 使用 printJS({printable: https://hwke.tbbug.com/images/phone/1899ed9346f64020ff4f9bbae6983952.jpg,type: image,imageStyle: width:100%;ma…

linux系统(centos、ubuntu、银河麒麟服务、uos、deepin)判断程序是否已安装,通用判断方法:使用所有应用和命令的判断

前言 项目中需要判断linux服务器中是否已经安装了某个服务 方法有很多种&#xff0c;但是很多都不通用&#xff0c; 脚本代码就不容易做成统一的 解决方案 用下面的脚本代码去进行判断 用jdk测试 脚本意思如下&#xff1a; 输入java -version命令&#xff0c;将返回的字…

react hooks 计数器

180秒倒计时 const [count, setCount] useState(0)setCount(180)useEffect(() > {clearTimeout(timer)timer setTimeout(() > {if (count > 1) {setCount(count - 1)} else {setIsSendEmail(false)}}, 1000)// eslint-disable-next-line}, [count]) import { useSta…

STM32 无法烧录

1. 一直显示芯片没连接上&#xff0c;检查连线也没问题&#xff0c;换了个ST-Link 烧录器还是连不上&#xff0c;然后又拿这个烧录器去其它板子上试下&#xff0c;就可以连接上&#xff0c;说明我连线没问题&#xff0c;烧录器也没问题&#xff0c;驱动什么的更是没问题&#x…

Kubernetes(K8S)简介

Kubernetes (K8S) 是什么 它是一个为 容器化 应用提供集群部署和管理的开源工具&#xff0c;由 Google 开发。Kubernetes 这个名字源于希腊语&#xff0c;意为“舵手”或“飞行员”。k8s 这个缩写是因为 k 和 s 之间有八个字符的关系。 Google 在 2014 年开源了 Kubernetes 项…

openCV实战-系列教程3:形态学操作(腐蚀操作/膨胀操作/开运算/闭运算/梯度计算/礼帽和黑帽)、源码解读

1、腐蚀操作 1.1 腐蚀 首先读进来并打印一张图 img cv2.imread(yzy.jpg) cv2.imshow(img, img) cv2.waitKey(0) cv2.destroyAllWindows() 这个图片出现了一些毛刺&#xff0c;看着挺难受 执行一个腐蚀操作&#xff0c;再将图片打印出来&#xff1a; kernel np.ones((3,3…

工厂方法模式介绍

韩敬海 设计模式&#xff08;Java版&#xff09; &#xff08;一&#xff09;定义 定义一个创建对象的接口&#xff0c;让子类决定实例化哪个类。工厂方法使一个类的实例化延迟到其子类。 工厂方法涉及的角色有&#xff1a; 1 .抽象工厂角色&#xff1a;工厂方法模式的核心&am…

从C语言到C++_34(C++11_下)可变参数+ lambda+function+bind+笔试题

目录 1. 可变参数模板 1.1 展开参数包 1.1.1 递归函数方式展开 1.1.2 逗号表达式展开 1.2 emplace相关接口 2. lambda表达式&#xff08;匿名函数&#xff09; 2.1 C11之前函数的缺陷 2.2 lambda表达式语法 2.3 函数对象与lambda表达式 3. 包装器 3.1 function包装器…

最新AI系统ChatGPT程序源码/微信公众号/H5端+搭建部署教程+完整知识库

一、前言 SparkAi系统是基于国外很火的ChatGPT进行开发的Ai智能问答系统。本期针对源码系统整体测试下来非常完美&#xff0c;可以说SparkAi是目前国内一款的ChatGPT对接OpenAI软件系统。 那么如何搭建部署AI创作ChatGPT&#xff1f;小编这里写一个详细图文教程吧&#xff01…

ARM DIY(三)板载串口和 LCD 调试

前言 今天焊接两大关键输入输出设备&#xff1a;串口和屏幕。 串口 串口部分使用 CP2102N 芯片&#xff08;USB 转 TTL&#xff09;&#xff0c;这样用一根数据线连接板子和 PC 就可以直接调试了。 焊接 CP2102 和 Type C 上电调试&#xff0c;串口可以正常输入输出。 看来…

css实现文字的渐变,适合大屏

1 在全局写一个全局样式&#xff0c;文字渐变 2 在组件中使用 CSS3利用-webkit-background-clip: text;实现文字渐变效果_css如何把盒子底部的文字变成透明渐变_I俩月亮的博客-CSDN博客 CSS 如何实现文字渐变色 &#xff1f;_css字体颜色渐变_一个水瓶座程序猿.的博客-CSDN博客…

ui设计师简历自我评价(合集)

UI设计最新面试题及答案 1、说说你是怎么理解UI的? UI是最直观的把产品展示展现在用户面前的东西&#xff0c;是一个产品的脸面。人开始往往是先会先喜欢上美好的事物后&#xff0c;在去深究内在的东西的。 那么也就意味着一个产品的UI首先要做的好看&#xff0c;无论风格是…

tensordataset 和dataloader取值

测试1 from torch.utils.data import TensorDataset,DataLoader import numpy as np import torch a np.array([[1,2,3],[2,3,3],[1,1,2],[10,10,10],[100,200,200],[-1,-2,-3]]) print(a)X torch.FloatTensor(a) print(X)dataset TensorDataset(X,X)测试2 from torch.uti…