我有点卡在这里,可以真正使用一些帮助.在我看来,在按钮上添加两行单独的文本应该很容易.但事实并非如此.有一种方法可以使用HTML标签,但这不允许您指定超出“大”和“小”的字体或文本大小.
这是我的按钮,它叫做’clicky’:
<?xml version="1.0" enCoding="utf-8"?><selector xmlns:androID="http://schemas.androID.com/apk/res/androID"> <item androID:drawable="@drawable/buttondown" androID:state_pressed="true" /> <item androID:drawable="@drawable/buttonup" /></selector>
以下是它在其中一个布局文件中显示的位置:
<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:orIEntation="vertical" androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent"><button androID:ID="@+ID/clicky" androID:layout_wIDth="137.5dip" androID:layout_height="wrap_content" androID:layout_alignParentRight="true" androID:layout_centerHorizontal="true" androID:layout_margintop="2dip" androID:layout_marginBottom="2dip" androID:layout_marginRight="1dip" androID:textSize="20dip" androID:background="@drawable/clicky" /> <ListVIEw androID:ID="@+ID/ListVIEw01" androID:layout_height="wrap_content" androID:layout_wIDth="fill_parent" androID:divIDer="#000000" androID:divIDerHeight="2dip" androID:layout_below="@+ID/separator"/></relativeLayout>
这是我在onCreate()方法中的内容:
Typeface customFont = Typeface.createFromAsset(getAssets(),"Fonts/zooper.ttf"); button mbutton=(button)findVIEwByID(R.ID.clicky); mbutton.setText("Hi There"); TextVIEw clicky = (TextVIEw)findVIEwByID(R.ID.clicky); clicky.setTypeface(customFont);
按钮中的文本是动态创建的,所以我必须从这里开始(现在它是静态的,但后来“Hi There”将被替换为变量).另一行文字将更小,静态并放在“Hi There”下面.我已经浏览了谷歌上的所有内容,甚至远远类似于我的问题,但我找不到能够适应我的问题的答案.
所以再次,我需要一个单独的按钮,两个单独的文本行,一个在另一个之上.顶行是大的,动态创建并使用自定义字体.较低的文本行将小得多,静态并且可以使用系统字体.
将linearLayout嵌套在按钮内是否真的太难了?
任何帮助将非常感激.
解决方法:
String s1;String s2;int n = s1.length();int m = s2.length;Typeface customFont = Typeface.createFromAsset(getAssets(),"Fonts/zooper.ttf");Spannable span = new SpannableString(s1 + "\n" + s2);//Big Font till you find `\n`span.setSpan(new CustomTypefaceSpan("", customFont), 0, n, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);//Small Font from `\n` to the endspan.setSpan(new relativeSizeSpan(0.8f), n, (n+m+1), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);yourbutton.setText(span);
总结 以上是内存溢出为你收集整理的android – 创建一个包含两行文本的自定义按钮,每行都有不同的字体全部内容,希望文章能够帮你解决android – 创建一个包含两行文本的自定义按钮,每行都有不同的字体所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)