Android 放大镜

本文介绍了如何在Android应用中实现放大镜功能,通过ShaderView.java和MainActivity.java两个关键文件的代码实现,提供了一个Android版的放大镜功能示例,并提供了下载链接。
摘要由CSDN通过智能技术生成

之前做过iOS下的放大镜功能,这个再来一个Android版的。下载地址:http://download.csdn.net/detail/qqmcy/7038411

ShaderView.java

package com.pactera.magnifierdemo;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Shader.TileMode;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.view.MotionEvent;
import android.view.View;

/**
 * 放大镜实现方式1
 * 
 * @author 杜甲同学
 * 
 */

public class ShaderView extends View {
	private final Bitmap bitmap;
	private final ShapeDrawable drawable;
	// 放大镜的半径

	private static
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
您可以使用 Android 中的 EditText 和 ImageView 组件来制作带放大镜查询标志的圆角搜索框。首先,您需要在布局文件中添加一个 EditText 组件和一个 ImageView 组件,然后将它们放在一个 LinearLayout 中。接下来,您可以使用 drawable 资源来定义圆角背景和放大镜图标。最后,您需要在代码中设置 EditText 的背景和 ImageView 的图标。以下是示例代码: 布局文件: ``` <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/search_box_bg" android:orientation="horizontal" android:padding="8dp"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_search"/> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/transparent" android:hint="Search"/> </LinearLayout> ``` drawable/search_box_bg.xml: ``` <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#FFFFFF"/> <corners android:radius="16dp"/> </shape> ``` drawable/ic_search.xml: ``` <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24"> <path android:fillColor="#000000" android:pathData="M15.5,14h-0.79l-0.28,-0.27c1.09,-1.29 1.75,-2.96 1.75,-4.73 0,-4.42 -3.58,-8 -8,-8s-8,3.58 -8,8 3.58,8 8,8c1.77,0 3.44,-0.66 4.73,-1.75l0.27,0.28v0.79l5,4.99c0.39,0.39 1.02,0.39 1.41,0l0.01,-0.01c0.39,-0.39 0.39,-1.02 0,-1.41l-4.99,-5zm-6.5,0c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5z"/> </vector> ``` Java 代码: ``` EditText editText = findViewById(R.id.edit_text); ImageView imageView = findViewById(R.id.image_view); imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Handle search button click } }); ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

杜甲同学

感谢打赏,我会继续努力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值