2024年安卓最全Android 实现搜索历史(1),2024年最新销售应届毕业生的面试题及答案

最后

感觉现在好多人都在说什么安卓快凉了,工作越来越难找了。又是说什么程序员中年危机啥的,为啥我这年近30的老农根本没有这种感觉,反倒觉得那些贩卖焦虑的都是瞎j8扯谈。当然,职业危机意识确实是要有的,但根本没到那种草木皆兵的地步好吗?

Android凉了都是弱者的借口和说辞。虽然 Android 没有前几年火热了,已经过去了会四大组件就能找到高薪职位的时代了。这只能说明 Android 中级以下的岗位饱和了,现在高级工程师还是比较缺少的,很多高级职位给的薪资真的特别高(钱多也不一定能找到合适的),所以努力让自己成为高级工程师才是最重要的。

所以,最后这里放上我耗时两个月,将自己8年Android开发的知识笔记整理成的Android开发者必知必会系统学习资料笔记,上述知识点在笔记中都有详细的解读,里面还包含了腾讯、字节跳动、阿里、百度2019-2021面试真题解析,并且把每个技术点整理成了视频和PDF(知识脉络 + 诸多细节)。

以上全套学习笔记面试宝典,吃透一半保你可以吊打面试官,只有自己真正强大了,有核心竞争力,你才有拒绝offer的权力,所以,奋斗吧!骚年们!千里之行,始于足下。种下一颗树最好的时间是十年前,其次,就是现在。

最后,赠与大家一句诗,共勉!

不驰于空想,不骛于虚声。不忘初心,方得始终。

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

myeditor.putString(“history”, builder.toString());

myeditor.commit();

}

}

public String[] getHistoryList() {

// 获取搜索记录文件内容

SharedPreferences sp = mContext.getSharedPreferences(“search_history”, 0);

String history = sp.getString(“history”, “”);

// 用逗号分割内容返回数组

String[] history_arr = history.split(“,”);

// 保留前50条数据

if (history_arr.length > 50) {

String[] newArrays = new String[50];

System.arraycopy(history_arr, 0, newArrays, 0, 50);

}

return history_arr;

}

/**

  • 清除搜索记录

*/

public void cleanHistory() {

SharedPreferences sp = mContext.getSharedPreferences(“search_history”, 0);

SharedPreferences.Editor editor = sp.edit();

editor.clear();

editor.commit();

}

}

4.Activity主要功能实现

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.view.ViewGroup;

import android.widget.Button;

import android.widget.EditText;

import android.widget.TextView;

import kemizhibo.rhkj.com.ijkpalaydemo.search.KeyBoardUtils;

import kemizhibo.rhkj.com.ijkpalaydemo.search.RegularUtils;

import kemizhibo.rhkj.com.ijkpalaydemo.search.SPUtils;

public class Main2Activity extends AppCompatActivity {

ZFlowLayout historyFl;

EditText autoSearch;

Button button_search;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main2);

historyFl = findViewById(R.id.history_fl);

autoSearch=findViewById(R.id.autoSearch);

button_search=findViewById(R.id.button_search);

initHistory();

button_search.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

if (KeyBoardUtils.isSoftShowing(Main2Activity.this)) {

KeyBoardUtils.hintKeyboard(Main2Activity.this);

}

String searchKey = autoSearch.getText().toString();

if (!isNullorEmpty(searchKey)) {

if (RegularUtils.hasEmoji(autoSearch.getText().toString())) {

//含有非法字符串

} else {

//搜索

String keyWord = autoSearch.getText().toString();

if (!isNullorEmpty(keyWord)) {

SPUtils.getInstance(Main2Activity.this).save(autoSearch.getText().toString());

}

initHistory();

}

} else {

//搜索为空

}

}

});

}

private boolean isNullorEmpty(String str) {

return str == null || “”.equals(str);

}

/**

  • 初始化 历史记录列表

*/

private void initHistory() {

final String[] data = SPUtils.getInstance(Main2Activity.this).getHistoryList();

ViewGroup.MarginLayoutParams layoutParams = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

layoutParams.setMargins(10, 10, 10, 10);

historyFl.removeAllViews();

for (int i = 0; i < data.length; i++) {

if (isNullorEmpty(data[i])) {

return;

}

//有数据往下走

final int j = i;

//添加分类块

View paramItemView = getLayoutInflater().inflate(R.layout.adapter_search_keyword, null);

TextView keyWordTv = paramItemView.findViewById(R.id.tv_content);

keyWordTv.setText(data[j]);

historyFl.addView(paramItemView, layoutParams);

keyWordTv.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

if (KeyBoardUtils.isSoftShowing(Main2Activity.this)) {

KeyBoardUtils.hintKeyboard(Main2Activity.this);

}

autoSearch.setText(data[j]);

autoSearch.setSelection(data[j].length());//光标在最后

if (!isNullorEmpty(data[j])) {

SPUtils.getInstance(Main2Activity.this).save(autoSearch.getText().toString());

}

//点击事件

}

});

// initautoSearch();

}

}

}

5.布局文件activity_main2.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

android:orientation=“vertical”

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”

tools:context=“kemizhibo.rhkj.com.ijkpalaydemo.Main2Activity”>

<Button

android:id=“@+id/button_search”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text=“搜索”

/>

<EditText

android:layout_width=“match_parent”

android:layout_height=“40dp”

android:id=“@+id/autoSearch”

/>

<kemizhibo.rhkj.com.ijkpalaydemo.ZFlowLayout

android:id=“@+id/history_fl”

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:layout_below=“@+id/title”

android:orientation=“vertical” />

adapter_search_keyword.xml

<?xml version="1.0" encoding="utf-8"?>

<TextView xmlns:android=“http://schemas.android.com/apk/res/android”

android:id=“@+id/tv_content”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginLeft=“15dp”

android:layout_marginTop=“12dp”

android:background=“#00f”

android:paddingBottom=“8dp”

android:paddingLeft=“12dp”

android:paddingRight=“12dp”

android:includeFontPadding=“false”

android:paddingTop=“8dp”

android:textColor=“#fff”

/>

ZFlowLayout.java

import android.content.Context;

import android.util.AttributeSet;

import android.view.View;

import android.view.ViewGroup;

import java.util.ArrayList;

import java.util.List;

/*****************************

  • @Copyright© 2014-2018

  • @Author:dengyalan

  • @Date:2018/1/16

  • @Description:自定义搜索标签布局

  • @Version:v1.0.0

*****************************/

public class ZFlowLayout extends ViewGroup {

/**

  • 存储所有子View

*/

private List<List> mAllChildViews = new ArrayList<>();

/**

  • 每一行的高度

*/

private List mLineHeight = new ArrayList<>();

public ZFlowLayout(Context context) {

this(context, null);

}

public ZFlowLayout(Context context, AttributeSet attrs) {

this(context, attrs, 0);

}

public ZFlowLayout(Context context, AttributeSet attrs, int defStyle) {

super(context, attrs, defStyle);

}

@Override

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

//父控件传进来的宽度和高度以及对应的测量模式

int sizeWidth = MeasureSpec.getSize(widthMeasureSpec);

int modeWidth = MeasureSpec.getMode(widthMeasureSpec);

int sizeHeight = MeasureSpec.getSize(heightMeasureSpec);

int modeHeight = MeasureSpec.getMode(heightMeasureSpec);

//如果当前ViewGroup的宽高为wrap_content的情况

//自己测量的宽度

int width = 0;

//自己测量的高度

int height = 0;

//记录每一行的宽度和高度

int lineWidth = 0;

int lineHeight = 0;

//获取子view的个数

int childCount = getChildCount();

for (int i = 0; i < childCount; i++) {

View child = getChildAt(i);

//测量子View的宽和高

measureChild(child, widthMeasureSpec, heightMeasureSpec);

//得到LayoutParams

MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams();

//子View占据的宽度

int childWidth = child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin;

//子View占据的高度

int childHeight = child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin;

//换行时候

if (lineWidth + childWidth > sizeWidth) {

//对比得到最大的宽度

width = Math.max(width, lineWidth);

//重置lineWidth

lineWidth = childWidth;

//记录行高

height += lineHeight;

lineHeight = childHeight;

} else {//不换行情况

//叠加行宽

lineWidth += childWidth;

//得到最大行高

lineHeight = Math.max(lineHeight, childHeight);

}

//处理最后一个子View的情况

if (i == childCount - 1) {

width = Math.max(width, lineWidth);

height += lineHeight;

}

}

//wrap_content

setMeasuredDimension(modeWidth == MeasureSpec.EXACTLY ? sizeWidth : width,

modeHeight == MeasureSpec.EXACTLY ? sizeHeight : height);

}

@Override

protected void onLayout(boolean changed, int l, int t, int r, int b) {

mAllChildViews.clear();

mLineHeight.clear();

//获取当前ViewGroup的宽度

int width = getWidth();

int lineWidth = 0;

int lineHeight = 0;

//记录当前行的view

List lineViews = new ArrayList();

int childCount = getChildCount();

for (int i = 0; i < childCount; i++) {

View child = getChildAt(i);

MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams();

int childWidth = child.getMeasuredWidth();

int childHeight = child.getMeasuredHeight();

//如果需要换行

if (childWidth + lineWidth + lp.leftMargin + lp.rightMargin > width) {

//记录LineHeight

mLineHeight.add(lineHeight);

//记录当前行的Views

mAllChildViews.add(lineViews);

//重置行的宽高

lineWidth = 0;

lineHeight = childHeight + lp.topMargin + lp.bottomMargin;

//重置view的集合

lineViews = new ArrayList();

}

lineWidth += childWidth + lp.leftMargin + lp.rightMargin;

lineHeight = Math.max(lineHeight, childHeight + lp.topMargin + lp.bottomMargin);

lineViews.add(child);

}

//处理最后一行

mLineHeight.add(lineHeight);

mAllChildViews.add(lineViews);

//设置子View的位置

int left = 0;

int top = 0;

//获取行数

int lineCount = mAllChildViews.size();

for (int i = 0; i < lineCount; i++) {

//当前行的views和高度

lineViews = mAllChildViews.get(i);

lineHeight = mLineHeight.get(i);

for (int j = 0; j < lineViews.size(); j++) {

View child = lineViews.get(j);

//判断是否显示

if (child.getVisibility() == View.GONE) {

continue;

}

MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams();

int cLeft = left + lp.leftMargin;

int cTop = top + lp.topMargin;

int cRight = cLeft + child.getMeasuredWidth();

int cBottom = cTop + child.getMeasuredHeight();

//进行子View进行布局

child.layout(cLeft, cTop, cRight, cBottom);

left += child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin;

}

总结

首先是感觉自己的基础还是不够吧,大厂好像都喜欢问这些底层原理。

另外一部分原因在于资料也还没有看完,一面时凭借那份资料考前突击恶补个几天居然也能轻松应对(在这里还是要感谢那份资料,真的牛),于是自我感觉良好,资料就没有怎么深究下去了。

之前的准备只涉及了Java、Android、计网、数据结构与算法这些方面,面对面试官对其他基础课程的考察显得捉襟见肘。

下一步还是要查漏补缺,进行针对性复习。

最后的最后,那套资料这次一定要全部看完,是真的太全面了,各个知识点都涵盖了,几乎我面试遇到的所有问题的知识点这里面都有!希望大家不要犯和我一样的错误呀!!!一定要看完!

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

.getMeasuredWidth() + lp.leftMargin + lp.rightMargin;

}

总结

首先是感觉自己的基础还是不够吧,大厂好像都喜欢问这些底层原理。

另外一部分原因在于资料也还没有看完,一面时凭借那份资料考前突击恶补个几天居然也能轻松应对(在这里还是要感谢那份资料,真的牛),于是自我感觉良好,资料就没有怎么深究下去了。

之前的准备只涉及了Java、Android、计网、数据结构与算法这些方面,面对面试官对其他基础课程的考察显得捉襟见肘。

下一步还是要查漏补缺,进行针对性复习。

最后的最后,那套资料这次一定要全部看完,是真的太全面了,各个知识点都涵盖了,几乎我面试遇到的所有问题的知识点这里面都有!希望大家不要犯和我一样的错误呀!!!一定要看完!
[外链图片转存中…(img-ygDC0Iyw-1715731904875)]

[外链图片转存中…(img-O5a3sEb3-1715731904876)]

[外链图片转存中…(img-Nr2FL3z3-1715731904876)]

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值