Dou*_*ing 3 android android-layout
我有点卡在这里,可以真正使用一些帮助.在我看来,将两个单独的文本行添加到按钮应该很容易.但事实并非如此.有一种方法可以使用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>
Run Code Online (Sandbox Code Playgroud)
以下是它在其中一个布局文件中显示的位置:
<?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>
Run Code Online (Sandbox Code Playgroud)
这是我在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);
Run Code Online (Sandbox Code Playgroud)
按钮中的文本是动态创建的,所以我必须从这里开始(现在它是静态的,但后来"Hi There"将被替换为变量).另一行文字将更小,静态并放在"Hi There"下面.我已经浏览了谷歌上的一切,甚至远远类似于我的问题,但我找不到能够适应我的问题的答案.
所以再次,我需要一个单独的按钮,两个单独的文本行,一个在另一个之上.顶行是大的,动态创建并使用自定义字体.较低的文本行将小得多,静态并且可以使用系统字体.
将LinearLayout嵌套在按钮内是否真的太难了?
任何帮助将非常感激.
Arc*_*pgc 11
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 end
span.setSpan(new RelativeSizeSpan(0.8f), n, (n+m+1), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
yourButton.setText(span);
Run Code Online (Sandbox Code Playgroud)