TextView内に順序付きリストを表示したい。例:
1)アイテム1
2)アイテム2
次のレイアウトを使用します。
<TextView
android:text="<ol><li>item 1\n</li><li>item 2\n</li></ol>
/>
私は得る:
- アイテム1
- アイテム2
箇条書きを数字に変更するにはどうすればよいですか?
ありがとう。
代わりにこの方法を使用できます。
• foo<br/>
• bar<br/>
• baz<br/>
これが私が使用する解決策です。これをコピーしてアクティビティに貼り付けて動作を確認することはできますが、本番環境ではすべての属性を変数で変更する必要があります。パディング パラメータをいじって、必要に応じてインデントすることができます。箇条書きリストが必要な場合は、数字の代わりに箇条書き文字を使用できます。
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/bullet1"
android:textStyle="bold"
android:layout_width="30dp"
android:gravity="right"
android:layout_height="wrap_content"
android:paddingRight="5dp"
android:text="1"
android:textSize="20dp" />
<TextView
android:id="@+id/bullet1Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:text="First bullet. First bullet. First bullet. First bullet. First bullet. First bullet. First bullet. First bullet. "
android:textSize="15dp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/bullet2"
android:textStyle="bold"
android:layout_width="30dp"
android:gravity="right"
android:layout_height="wrap_content"
android:paddingRight="5dp"
android:text="2"
android:textSize="20dp" />
<TextView
android:id="@+id/bullet2Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:text="Second bullet. Second bullet. Second bullet. Second bullet. Second bullet. Second bullet. Second bullet. "
android:textSize="15dp" />
</LinearLayout>
LeadingMarginSpanを直接使用できます
例えば
String[] textArray = {
"dfsdljjlfsdsdfjsdjldssdfidfsjdljasdfjfds\n",
"sdfjdfjlkfdjdfkfjiwejojodljfldsjodsjfsdjdlf\n",
"djsdfjsdffjdflljfjsadfdjfldfjl"
};
SpannableStringBuilder content = new SpannableStringBuilder();
int number = 1;
for (String t1 : textArray) {
int contentStart = content.length();
String leadingString = number + ". ";
content.append(leadingString);
content.append(t1);
int contentEnd = content.length();
content.setSpan(
new LeadingMarginSpan.Standard(0, 66),
contentStart,
contentEnd,
Spannable.SPAN_INCLUSIVE_EXCLUSIVE
);
number++;
}