我正在创建一个应用程序,它有一些描述有步骤.例如:
如何转移:
- 你有信用卡吗?
- 如果你不做假的
- 然后将其插入ATM
- 看着它爆炸
如何捕鱼:
越来越长了......
这些描述(步骤)将显示在scrollview中,现在我使用java,setText使用"\n"和""额外的空白空间来欺骗diplay.然而,这不适用于不同的分辨率.如何使textview显示这样的东西?
基于答案,我尝试了这个:.xml布局
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="16dp"
android:layout_marginTop="16dp" >
<TextView
android:id="@+id/tvCBAjud"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/transfer"
android:textSize="16sp"
/>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
并定义字符串:
<string name="transfer">how to transfer \n
<ul>
<li>-Do you have credit card</li>
<li>-If you dont make a fake one</li>
<li>-Then insert it to ATM</li>
<li>-And watch it explode</li>
</ul></string>
Run Code Online (Sandbox Code Playgroud)
但输出变为:
How to transfer -Do you have credit card -If you dont make a fake one -Then insert it to ATM -And watch it explode
Run Code Online (Sandbox Code Playgroud)
如果您的文本是静态的,那么你可以扩展TextView到自动在前面加上BulletSpan你的面前android:text:
layout.xml
<BulletTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Orange" />
<BulletTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Banana" />
Run Code Online (Sandbox Code Playgroud)
BulletTextView.java
/**
* {@link TextView} that automatically adds bullet point to text if set in layout
*/
public class BulletTextView extends TextView {
public BulletTextView(Context context) {
super(context);
addBullet();
}
public BulletTextView(Context context, AttributeSet attrs) {
super(context, attrs);
addBullet();
}
public BulletTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
addBullet();
}
public BulletTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
addBullet();
}
private void addBullet() {
CharSequence text = getText();
if (TextUtils.isEmpty(text)) {
return;
}
SpannableString spannable = new SpannableString(text);
spannable.setSpan(new BulletSpan(16), 0, text.length(), 0);
setText(spannable);
}
}
Run Code Online (Sandbox Code Playgroud)
您可以通过为缩进添加自定义属性来进一步自定义此项.
您可以使用Unicode作为项目符号
TextView tv = (TextView) findViewById(R.id.textView1);
String circle = "\u25CF";
String sentence = circle + " " + "Hello its me"+ "\n";
tv.setText(sentence);
Run Code Online (Sandbox Code Playgroud)
通过更改Unicode和Unicode表使用任何符号,项目符号等.http://unicode-table.com/en/#box-drawing
| 归档时间: |
|
| 查看次数: |
8499 次 |
| 最近记录: |