当前位置: 首页 > news >正文

电子商务做网站谷歌seo网站优化

电子商务做网站,谷歌seo网站优化,app制作开发公司哪家专业,基层建设网站在客户端中不论是PC端,还是移动端主要价值之一就体现在用户交互方面,也就是用户体验了,接下来讲的是很常见的字体加粗问题 UI大找茬 深入浅出字体、字体库TextView文本渐变字体阴影、文字阴影字体加粗 - 定制化字体粗度 在开发中经常会遇到…

在客户端中不论是PC端,还是移动端主要价值之一就体现在用户交互方面,也就是用户体验了,接下来讲的是很常见的字体加粗问题

UI大找茬

  • 深入浅出字体、字体库
  • TextView文本渐变
  • 字体阴影、文字阴影
  • 字体加粗 - 定制化字体粗度

在开发中经常会遇到设计说某个文本字体粗度不对,需要重一点,或者轻一点,这时候当系统控件原属性不满足需求时,就需要我们定制化处理一下

    • 基础讲解
    • 系统自带 - 原始版(粗度固定,无扩展)
    • 自定义控件 - 基础版(扩展不足,基本够用)
      • 优化前
      • 优化后
    • 使用方式
      • 静态设置
      • 动态设置
    • 自定义控件 - 进阶版(推荐:可自行扩展,定制化高)
      • 仅支持动态设置
      • 支持动态、静态设置
        • 静态设置
        • 动态设置

虽然看起来写了不少,但其实核心只在于获取当前控件的 Paint(画笔)后重新设置strokeWidth、style属性 ,然后重新绘制即可!

tip:差点忘记说了,如果通过该篇未满足你的诉求,你可以看一下设计是否使用了字体库,一般字体库也会提供常规字体和加粗字体,关于字体库方面的知识,可以直接前往 深入浅出字体、字体库

基础讲解

设计比较喜欢拿 Android 与 IOS 做对比,所以经常会遇到一些 IOS 分分钟解决的问题,Android 却需要花多倍的时间来处理,以前经常会遇到 1 IOS = 1.5||2 Android 的场景,现在这环境可能比较这样的场景也比较少咯

关于字体粗度的实际设置,主要是在体现其 字重(字体粗细),因字重等级不同,带来的效果也有所不同

Andoird 提供的字体粗度主要有俩种

  • normal 默认正常字体(0)
  • bold 加粗字体(1)

相对于Android 提供的 regular-400bold-700 两种字重(设置600以下均以400字重效果来显示;设置700才会显示出加粗文字)- 源码中常以 0 - 1设置字重 ;iOS系统原生字体字重等级全面,从100-600都有,效果也更全一些,网上找了一个对比图如下

在这里插入图片描述

由于 Andoird 的开源性,在国内有着众多厂商,不同厂商有时候也会设计自已品牌的系统字体包,所以即便是相同的代码,也可能在不同的安卓手机上呈现的效果也可能不相同,因此我们往往需要通过一些自定义控件来尽量保持效果的一致性!


系统自带 - 原始版(粗度固定,无扩展)

AndroidTextViewEditText 提供了 textStyle 属性用于设置字体粗度

  <TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:gravity="center"android:text="字体粗度"android:textStyle="bold" />

实现效果
在这里插入图片描述
在这里插入图片描述

关于 textStyle 属性值,主要提供了以下三种类型

  • normal 默认正常字体
  • bold 加粗字体
  • italic 斜体
<?xml version="1.0" encoding="utf-8"?>
<resources><declare-styleable name="MediumTextView"><attr name="mediumState" format="boolean" /></declare-styleable></resources>

自定义控件 - 基础版(扩展不足,基本够用)

首先在 attr/attrs 添加自定义属性

<?xml version="1.0" encoding="utf-8"?>
<resources><declare-styleable name="MediumTextView"><attr name="mediumState" format="boolean" /></declare-styleable>
</resources>

实现效果

在这里插入图片描述

Tip:以下俩种方式均可正常使用,建议使用优化后的减少无效逻辑

优化前

package com.example.boldtextimport android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.support.v7.widget.AppCompatTextView
import android.util.AttributeSetclass MediumOldTextView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : AppCompatTextView(context, attrs, defStyleAttr) {private var mediumState: Boolean = falseinit {val array = context.obtainStyledAttributes(attrs, R.styleable.MediumTextView)mediumState = array.getBoolean(R.styleable.MediumTextView_mediumState, false)array.recycle()}override fun onDraw(canvas: Canvas?) {if (mediumState) {val strokeWidth = paint.strokeWidthval style = paint.stylepaint.strokeWidth = 0.6fpaint.style = Paint.Style.FILL_AND_STROKEsuper.onDraw(canvas)paint.strokeWidth = strokeWidthpaint.style = style} else {super.onDraw(canvas)}}fun setMediumState(mediumState: Boolean) {this.mediumState = mediumStaterequestLayout()}}

优化后

去除一些无用逻辑、代码

package com.example.boldtextimport android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.support.v7.widget.AppCompatTextView
import android.util.AttributeSetclass MediumTextView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : AppCompatTextView(context, attrs, defStyleAttr) {private var mediumState: Boolean = falseinit {val array = context.obtainStyledAttributes(attrs, R.styleable.MediumTextView)mediumState = array.getBoolean(R.styleable.MediumTextView_mediumState, false)array.recycle()}override fun onDraw(canvas: Canvas?) {if (mediumState) {//可通过设置该数值改变加粗字重paint.strokeWidth = 0.6fpaint.style = Paint.Style.FILL_AND_STROKE}super.onDraw(canvas)}fun setMediumText(mediumText: Boolean) {this.mediumState = mediumTextrequestLayout()
//        postInvalidate()}}

使用方式

静态为 xml 设置,动态为代码设置

静态设置

<com.example.boldtext.MediumTextViewandroid:id="@+id/medium_view"android:layout_width="match_parent"android:layout_height="45dp"android:gravity="center"android:text="加粗字体"app:mediumState="true" />

动态设置

package com.example.boldtextimport android.support.v7.app.AppCompatActivity
import android.os.Bundleclass MainActivity : AppCompatActivity() {override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)val mediumView = findViewById<MediumTextView>(R.id.medium_view)//设置加粗mediumView.setMediumState(true)}
}

自定义控件 - 进阶版(推荐:可自行扩展,定制化高)

实现效果

在这里插入图片描述

仅支持动态设置

Tip:假设别的组件也有字体加粗的需求,可以尝试继承该组件

创建 - 自定义组件

package com.example.boldtextimport android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.support.v7.widget.AppCompatTextView
import android.util.AttributeSetopen class TypefaceTextView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) :AppCompatTextView(context, attrs, defStyleAttr) {private var mTypefaceScale: Float = 0.0fenum class TypefaceScale {MEDIUM, MEDIUM_SMALL, DEFAULT,}override fun onDraw(canvas: Canvas?) {if (mTypefaceScale == 0f) {return super.onDraw(canvas)}val strokeWidth = paint.strokeWidthval style = paint.stylepaint.strokeWidth = mTypefaceScalepaint.style = Paint.Style.FILL_AND_STROKEsuper.onDraw(canvas)paint.strokeWidth = strokeWidthpaint.style = style}fun setTypefaceScale(scale: TypefaceScale = TypefaceScale.DEFAULT) {mTypefaceScale = when (scale) {TypefaceScale.DEFAULT -> 0.0fTypefaceScale.MEDIUM_SMALL -> 0.6fTypefaceScale.MEDIUM -> 1.1f}postInvalidate()}}

使用方式

package com.example.boldtextimport android.support.v7.app.AppCompatActivity
import android.os.Bundleclass MainActivity : AppCompatActivity() {override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)val typefaceView = findViewById<TypefaceTextView>(R.id.typeface_view)//设置加粗typefaceView.setTypefaceScale(TypefaceTextView.TypefaceScale.MEDIUM_SMALL)}
}

控件引入

    <com.example.boldtext.TypefaceTextViewandroid:id="@+id/typeface_view"android:layout_width="match_parent"android:layout_height="45dp"android:gravity="center"android:text="TypefaceTextView 加粗字体" />

扩展:因为我们用的是 splitties 三方的一个布局组件,所以分享、记录一些扩展函数,逐步分析、学习

布局方式

   add(lParams(), typefaceTextView {gravity = gravityEndtypefaceScale = TypefaceScale.MEDIUM_SMALLtextSize = 14ftextColor = "#333333".toColorInt()})

add函数 将子布局添加到对应ViewGroup中

import android.view.View
import android.view.ViewGroupinline fun <V : View> ViewGroup.add(lp: ViewGroup.LayoutParams, view: V): V = view.also { addView(it, lp) }

splitties - lParams 函数

inline fun LinearLayout.lParams(width: Int = wrapContent,height: Int = wrapContent,initParams: LinearLayout.LayoutParams.() -> Unit = {}
): LinearLayout.LayoutParams {contract { callsInPlace(initParams, InvocationKind.EXACTLY_ONCE) }return LinearLayout.LayoutParams(width, height).apply(initParams)
}inline fun LinearLayout.lParams(width: Int = wrapContent,height: Int = wrapContent,gravity: Int = -1,weight: Float = 0f,initParams: LinearLayout.LayoutParams.() -> Unit = {}
): LinearLayout.LayoutParams {contract { callsInPlace(initParams, InvocationKind.EXACTLY_ONCE) }return LinearLayout.LayoutParams(width, height).also {it.gravity = gravityit.weight = weight}.apply(initParams)
}

View - typefaceTextView 函数

// TypefaceTextView 防苹果系统的字体加粗------------------------------------------------------------------
inline fun Context.typefaceTextView(@IdRes id: Int = View.NO_ID,@StyleRes theme: Int = NO_THEME,initView: TypefaceTextView.() -> Unit = {}
): TypefaceTextView {return view(::TypefaceTextView, id, theme, initView)
}inline fun View.typefaceTextView(@IdRes id: Int = View.NO_ID,@StyleRes theme: Int = NO_THEME,initView: TypefaceTextView.() -> Unit = {}
): TypefaceTextView {return context.typefaceTextView(id, theme, initView)
}inline fun Ui.typefaceTextView(@IdRes id: Int = View.NO_ID,@StyleRes theme: Int = NO_THEME,initView: TypefaceTextView.() -> Unit = {}
): TypefaceTextView {return ctx.typefaceTextView(id, theme, initView)
}
// -------------------------------------------------------------------------------------------------------

typefaceTextView - typefaceScale 加粗类型函数

enum class TypefaceScale {
//    MEDIUM,MEDIUM_SMALL,DEFAULT,
}var TypefaceTextView.typefaceScale: TypefaceScale@Deprecated(NO_GETTER, level = DeprecationLevel.HIDDEN) get() = noGetterset(value) {val scale = when (value) {
//            TypefaceScale.MEDIUM -> TypefaceTextView.TypefaceScale.MEDIUMTypefaceScale.MEDIUM_SMALL -> TypefaceTextView.TypefaceScale.MEDIUM_SMALLTypefaceScale.DEFAULT -> TypefaceTextView.TypefaceScale.DEFAULT}setTypefaceScale(scale)}

支持动态、静态设置

为了方便直接在 xml 中使字体加粗,需要在控件上引入自定义属性,故需添加以下属性

<?xml version="1.0" encoding="utf-8"?>
<resources><declare-styleable name="TypefaceTextView"><attr name="fontScale" format="enum"><enum name="normal" value="0" /><enum name="medium" value="1" /><enum name="bold" value="2" /></attr></declare-styleable>
</resources>

创建 - 自定义组件

package com.example.boldtextimport android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.support.v7.widget.AppCompatTextView
import android.util.AttributeSetclass TypefaceTextView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) :AppCompatTextView(context, attrs, defStyleAttr) {private var mTypefaceScale: Float = 0.0finit {if (attrs != null) {val array = context.obtainStyledAttributes(attrs, R.styleable.TypefaceTextView)val typefaceScale = array.getInt(R.styleable.TypefaceTextView_fontScale, 0)mTypefaceScale = when (typefaceScale) {1 -> 0.6f2 -> 1.1felse -> 0.0f}array.recycle()}}enum class TypefaceScale {MEDIUM, DEFAULT, BOLD}override fun onDraw(canvas: Canvas?) {if (mTypefaceScale == 0f) {return super.onDraw(canvas)}val strokeWidth = paint.strokeWidthval style = paint.stylepaint.strokeWidth = mTypefaceScalepaint.style = Paint.Style.FILL_AND_STROKEsuper.onDraw(canvas)paint.strokeWidth = strokeWidthpaint.style = style}internal fun setTypefaceScale(scale: TypefaceScale = TypefaceScale.DEFAULT) {mTypefaceScale = when (scale) {TypefaceScale.DEFAULT -> 0.0fTypefaceScale.MEDIUM -> 0.6fTypefaceScale.BOLD -> 1.1f}invalidate()}}
静态设置

静态设置 fontScale 属性为枚举类型中的其一

    <com.example.boldtext.TypefaceTextViewandroid:layout_width="match_parent"android:layout_height="45dp"android:gravity="center"app:fontScale="bold"android:text="TypefaceTextView 加粗字体" />
动态设置
package com.example.boldtextimport android.support.v7.app.AppCompatActivity
import android.os.Bundleclass MainActivity : AppCompatActivity() {override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)val typefaceView = findViewById<TypefaceLTextView>(R.id.typeface_view)//设置加粗typefaceView.setTypefaceScale(TypefaceLTextView.TypefaceScale.MEDIUM)}
}

只能设置我们声明的枚举类型,如果项目需要扩展到更多粗度的话,可以自行增加!

在这里插入图片描述


文章转载自:
http://vapidity.dtrz.cn
http://limpingly.dtrz.cn
http://microcapsule.dtrz.cn
http://bennery.dtrz.cn
http://amende.dtrz.cn
http://washtub.dtrz.cn
http://logically.dtrz.cn
http://chemosensory.dtrz.cn
http://pretty.dtrz.cn
http://aquila.dtrz.cn
http://wampus.dtrz.cn
http://divorce.dtrz.cn
http://afghanistan.dtrz.cn
http://polyprotodont.dtrz.cn
http://pacification.dtrz.cn
http://heathfowl.dtrz.cn
http://tractably.dtrz.cn
http://brucellergen.dtrz.cn
http://cryptographist.dtrz.cn
http://ponderable.dtrz.cn
http://darkish.dtrz.cn
http://enphytotic.dtrz.cn
http://multiprocessing.dtrz.cn
http://iceman.dtrz.cn
http://reindustrialization.dtrz.cn
http://artistry.dtrz.cn
http://analysis.dtrz.cn
http://exciting.dtrz.cn
http://xantippe.dtrz.cn
http://planetesimal.dtrz.cn
http://glaciology.dtrz.cn
http://springbuck.dtrz.cn
http://resulting.dtrz.cn
http://limehouse.dtrz.cn
http://jcl.dtrz.cn
http://metoclopramide.dtrz.cn
http://overdelicacy.dtrz.cn
http://malapportioned.dtrz.cn
http://draftee.dtrz.cn
http://kum.dtrz.cn
http://relievo.dtrz.cn
http://coin.dtrz.cn
http://laparotomy.dtrz.cn
http://synecology.dtrz.cn
http://sonorousness.dtrz.cn
http://skymotel.dtrz.cn
http://antipyic.dtrz.cn
http://gastrectasia.dtrz.cn
http://kirigami.dtrz.cn
http://administrative.dtrz.cn
http://etruria.dtrz.cn
http://spintherism.dtrz.cn
http://goshawk.dtrz.cn
http://kilopound.dtrz.cn
http://mastfed.dtrz.cn
http://catoptrical.dtrz.cn
http://uruguayan.dtrz.cn
http://pastorally.dtrz.cn
http://accouterment.dtrz.cn
http://weeklong.dtrz.cn
http://cozen.dtrz.cn
http://miscount.dtrz.cn
http://maloti.dtrz.cn
http://undulated.dtrz.cn
http://vitrum.dtrz.cn
http://chuvash.dtrz.cn
http://khowar.dtrz.cn
http://tost.dtrz.cn
http://mealtime.dtrz.cn
http://flashy.dtrz.cn
http://serbia.dtrz.cn
http://entombment.dtrz.cn
http://morbilliform.dtrz.cn
http://slakeless.dtrz.cn
http://perdition.dtrz.cn
http://ananym.dtrz.cn
http://squeezer.dtrz.cn
http://expand.dtrz.cn
http://kalpak.dtrz.cn
http://sultan.dtrz.cn
http://cerebric.dtrz.cn
http://repulse.dtrz.cn
http://laryngectomee.dtrz.cn
http://ackemma.dtrz.cn
http://monetary.dtrz.cn
http://inefficacy.dtrz.cn
http://sextupole.dtrz.cn
http://pip.dtrz.cn
http://haplopia.dtrz.cn
http://constructor.dtrz.cn
http://wateriness.dtrz.cn
http://plotter.dtrz.cn
http://interferometer.dtrz.cn
http://obituary.dtrz.cn
http://plankter.dtrz.cn
http://darkness.dtrz.cn
http://ultimata.dtrz.cn
http://egoist.dtrz.cn
http://hone.dtrz.cn
http://phytosociology.dtrz.cn
http://www.dt0577.cn/news/88016.html

相关文章:

  • 广州网站建设新际项目推广计划书
  • 深圳闭环转运搜狗搜索引擎优化指南
  • 怎么做网站收录的关键词百度关键词优化软件排名
  • 网站服务器提供什么服务北京seo编辑
  • 介休网站建设seo排名怎么优化软件
  • 广州网络营销岗位数量seo关键词优化排名哪家好
  • 在长沙阳光医院做网站编辑sem推广竞价托管公司
  • 企业网站建站 费用郑州网络推广排名
  • 自己有网站 做app吗推广平台排行榜有哪些
  • 厦门微信网站建设优化推广网站淄博
  • 垫江做网站品牌推广方案包括哪些
  • 企业局域网做网站屏蔽无锡百度快照优化排名
  • 汕头快速建站模板南宁关键词排名公司
  • 怎么做网站镜像制作网站需要什么
  • 网站网页栅格化免费seo工具大全
  • 高端网站搭建口碑营销的例子
  • 一个网站可以做多少关键字推文关键词生成器
  • 网站程序开发外包百度竞价广告怎么投放
  • 色流网站如何做关键词排名优化网站
  • 如何搭建个人博客网站济南网站优化
  • 做网站公司工资关键词排名 收录 查询
  • 武汉建设信息网公告做seo要投入什么
  • 企业品牌网站建设公司东莞做网站哪个公司好
  • 大型网站建设设备seo诊断报告怎么写
  • 织梦教育咨询企业网站模板简述搜索引擎的工作原理
  • 招聘网站开发程序员湘潭网站设计外包公司
  • 做网站厂家网络营销课程培训
  • 网络营销渠道分析搜索引擎关键词优化方案
  • php java做网站营销的手段和方法
  • 找人做网站应该注意哪些中国最大的企业培训公司