
TextView作为Android开发中的基础控件,在日常开发中我们频繁使用到TextView的一些功能.这里就简单总结了一下开发中常用的一些功能
/**
* 中间划线的效果
* @param textView
*/
public static void setStrikethrough(TextView textView){
textView.setPaintFlags(Paint.STRIKE_THRU_TEXT_FLAG);
}
/**
* Html 方式设置不同文字大小
* @param textview
* @param money
*/
public static void setMoney(TextView textview,double money){
String moneyss= "<font color='#FFFFFF'><small>¥ </small></font><font color='#FFFFFF'><big>%s</big></font>";
String moneyContent=String.format(moneyss,getNumDiff(money));
textview.setText(Html.fromHtml(moneyContent));
}
/**
* span 方式设置 不同字体大小
* @param textview
* @param money
* @param sizeSpan 字体大小 大于100 是比设置的字体大 小于100是比设置的小
*/
public static void setMoney(TextView textview,double money,int sizeSpan){
String moneyss= "¥ %s";
String moneyContent=String.format(moneyss,getNumDiff(money));
SpannableString spannableString = new SpannableString(moneyContent);
spannableString.setSpan(new AbsoluteSizeSpan(sizeSpan), 0, 2, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
textview.setText(spannableString);
}
/**
* 数量转换
*/
public static String getNumDiff(double count) {
String fansNum = "";
if (count >= 0 && count < 10000) {
fansNum = count + "";
} else if (count >= 10000 && count < 10000000) {
if (count / 1000 % 10 != 0) {
float num = (float) count / 10000;
DecimalFormat decimalFormat = new DecimalFormat("0.0");
fansNum = decimalFormat.format(num).concat("万");
} else {
fansNum = (count / 10000) + "万";
}
} else if (count >= 10000000) {
fansNum = "1000万";
}
return fansNum;
}
/**
* 设置小数点以后文字大小
* @param textview
* @param money
* @param sizeSpan 字体大小 大于100 是比设置的字体大 小于100是比设置的小
*/
public static void setMoneyTextView(TextView textview,double money,int sizeSpan){
String moneyss= "¥ %.2f";
String moneyContent=String.format(moneyss,money);
int index=moneyContent.indexOf(".");
SpannableString spannableString = new SpannableString(moneyContent);
spannableString.setSpan(new AbsoluteSizeSpan(sizeSpan), index, moneyContent.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
textview.setText(spannableString);
}
/**
* html方式
* 设置字体的不同颜色
* @param textview
* @param content
*/
public static void setColor(TextView textview,String content){
// String str6 = "<font color=\"#00ff00\">我的</font><font color=\"#0000ff\">作业完成了</font>";
String moneyss= "%s <font color=\"#FF0000\">%s</font>";
String strigContent=String.format(moneyss,"我的","作业完成了");
textview.setText(Html.fromHtml(strigContent));
}
/**
* 设置文字颜色 span 方式
* @param textview
* @param content
* @param endSize
*/
public static void setColor(TextView textview,String content,int endSize){
SpannableString spannableString = new SpannableString(content);
spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#FF0000")), endSize, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
textview.setText(spannableString);
}
/**
* 设置图片
* @param mContext
* @param textview
* @param content
*/
public static void setDrawable(Context mContext, TextView textview, String content){
SpannableString spannableString = new SpannableString(" "+content);
//这只图片的宽高
Drawable drawable = mContext.getResources().getDrawable(R.mipmap.ic_launcher);
drawable.setBounds(0, 0, 100, 100);
ImageSpan imageSpan = new ImageSpan(drawable);
spannableString.setSpan(imageSpan, 0, 1, ImageSpan.ALIGN_BASELINE);
Drawable drawable2 = mContext.getResources().getDrawable(R.mipmap.ic_launcher);
drawable2.setBounds(0, 0, 100, 100);
ImageSpan imageSpan2 = new ImageSpan(drawable2);
spannableString.setSpan(imageSpan2, 2, 3, ImageSpan.ALIGN_BASELINE);
textview.setText(spannableString);
}
注意
图文混排建议web加载标签方式实现
简单的总结了一下TextView常见的一些展示样式,还有一些处理相对麻烦的,比如扩展TextView 指定类型文字高亮展示这里没做展开.后期继续总结.高亮和扩展的TextView的自定义库放在下边了
只是想确保我理解了事情。据我目前收集到的信息,Cucumber只是一个“包装器”,或者是一种通过将事物分类为功能和步骤来组织测试的好方法,其中实际的单元测试处于步骤阶段。它允许您根据事物的工作方式组织您的测试。对吗? 最佳答案 有点。它是一种组织测试的方式,但不仅如此。它的行为就像最初的Rails集成测试一样,但更易于使用。这里最大的好处是您的session在整个Scenario中保持透明。关于Cucumber的另一件事是您(应该)从使用您的代码的浏览器或客户端的角度进行测试。如果您愿意,您可以使用步骤来构建对象和设置状态,但通常您
我正在使用RubyonRails3.0.9,我想生成一个传递一些自定义参数的link_toURL。也就是说,有一个articles_path(www.my_web_site_name.com/articles)我想生成如下内容:link_to'Samplelinktitle',...#HereIshouldimplementthecode#=>'http://www.my_web_site_name.com/articles?param1=value1¶m2=value2&...我如何编写link_to语句“alàRubyonRailsWay”以实现该目的?如果我想通过传递一些
文章目录git常用命令(简介,详细参数往下看)Git提交代码步骤gitpullgitstatusgitaddgitcommitgitpushgit代码冲突合并问题方法一:放弃本地代码方法二:合并代码常用命令以及详细参数gitadd将文件添加到仓库:gitdiff比较文件异同gitlog查看历史记录gitreset代码回滚版本库相关操作远程仓库相关操作分支相关操作创建分支查看分支:gitbranch合并分支:gitmerge删除分支:gitbranch-ddev查看分支合并图:gitlog–graph–pretty=oneline–abbrev-commit撤消某次提交git用户名密码相关配置g
我想找到在某些文本中找到一些(让它是两个)句子的好方法。什么会更好-使用正则表达式或拆分方法?你的想法?应JeremyStein的要求-有一些例子示例:输入:ThefirstthingtodoistocreatetheCommentmodel.We’llcreatethisinthenormalway,butwithonesmalldifference.IfwewerejustcreatingcommentsforanArticlewe’dhaveanintegerfieldcalledarticle_idinthemodeltostoretheforeignkey,butinthis
我正在构建一个应用程序,想知道是否将未使用的对象设置为nil是生产级编码中的常见做法。我知道这只是垃圾收集器的提示,并不总是处理对象。 最佳答案 根据这个thread如果您使用完一个成员对象,将其设置为nil将引发被引用对象被垃圾回收。如果它是局部变量,方法exit将做同样的事情。也就是说,如果您要求将成员显式设置为nil,我会质疑您的设计。 关于ruby-将对象设置为nil是否很常见?,我们在StackOverflow上找到一个类似的问题: https://
我最近与一位同事讨论了以下Ruby语法:value=ifa==0"foo"elsifa>42"bar"else"fizz"end我个人并没有看到太多这种逻辑,但我的同事指出,这实际上是一种相当普遍的Rubyism。我试着用谷歌搜索这个主题,但没有找到任何文章、页面或SO问题来讨论它,这让我相信这可能是一种非常实际的技术。然而,另一位同事发现语法令人困惑,而是将上面的逻辑写成这样:ifa==0value="foo"elsifa>42value="bar"elsevalue="fizz"end缺点是value=的重复声明和隐式elsenil的丢失,如果我们想使用它的话。这也感觉它与Ruby
在Rails自动生成的功能测试(test/functional/products_controller_test.rb)中,我看到以下代码:classProductsControllerTest我的问题是:方法调用products()在哪里/如何定义?products(:one)到底是什么意思?看代码,大概意思是“创建一个产品”,但是它是如何工作的呢?注意我是Ruby/Rails的新手,如果这些是微不足道的问题,我深表歉意。 最佳答案 如果您查看test/fixtures文件夹,您会看到一个products.yml文件。这是在您创建
在我的一些Controller中,我有一个before_filter检查用户是否登录?用于CRUD操作。application.rbdeflogged_in?unlesscurrent_userredirect_toroot_pathendendprivatedefcurrent_user_sessionreturn@current_user_sessionifdefined?(@current_user_session)@current_user_session=UserSession.findenddefcurrent_userreturn@current_userifdefine
我正在使用ruby1.8.7。p=lambda{return10;}deflab(block)puts'before'putsblock.callputs'after'endlabp以上代码输出为before10after我将相同的代码重构到这里deflab(&block)puts'before'putsblock.callputs'after'endlab{return10;}现在我收到LocalJumpError:意外返回。对我来说,这两个代码都在做同样的事情。是的,在第一种情况下我传递了一个过程,在第二种情况下我传递了一个block。但是&block将该block转换为pro
我在Ruby中有一个哈希:hash=Hash.new里面有一些键值对,比如说:hash[1]="One"hash[2]="Two"如果散列包含键2,那么我想将“Bananas”添加到它的值中。如果散列没有键2,我想创建一个新的键值对2=>"Bananas"。我知道我可以通过首先使用has_key?检查散列是否具有key2来做到这一点,然后采取相应的行动。但这需要一个if语句和不止一行。那么是否有一种简单、优雅的单行代码可以实现这一目标? 最佳答案 这个有效:hash[2]=(hash[2]||'')+'Bananas'如果您希望所有