我有一个TextView,我用strings.xml中的字符串资源填充文本。字符串资源包含< li>在TextView中创建项目符号列表的元素。我的问题是我想控制子弹列表中跨越多行的行的缩进。默认情况下,文本不会缩进子弹,所以它看起来很难看。是否可以使用样式参数执行此操作或以其他方式创建项目符号?
提前致谢。
编辑: 真的回答了吗?我在制作子弹列表时没有任何问题,如这些链接所述,但我在设置布局方面遇到了问题。缩进是这样的:
我希望“线条”至少开始缩进到子弹后的文本。这就是我试图实现的目标。
答案 0 :(得分:23)
我很惊讶似乎没有人遇到这个问题。我的意思是,子弹列表在约会对话框,常见问题解答等中不常见,并且子弹不必包含太多文本以跨越多行并遇到此问题。
无论如何,我现在必须这样解决它:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:id="@+id/ScrollViewTipsLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/TipsLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableLayout
android:layout_height="wrap_content"
android:id="@+id/TableLayout01"
android:layout_width="wrap_content"
>
<TableRow>
<TextView android:id="@+id/tvIngress"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@+string/tv_picking_content_ingress"
android:layout_span="2"
android:singleLine="false"
android:layout_weight="1"
/>
</TableRow>
<TableRow>
<TextView android:id="@+id/tvCleaningDot1"
android:layout_height="wrap_content"
android:text="•"
android:singleLine="false"
/>
<TextView android:id="@+id/tvCleaningFirst"
android:layout_height="wrap_content"
android:text="@+string/tv_picking_content_first"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="left"
android:singleLine="false"
/>
</TableRow>
<TextView android:id="@+id/tvCleaningDot2"
android:layout_height="wrap_content"
android:text="•"
android:singleLine="false"
/>
<TextView android:id="@+id/tvCleaningSecond"
android:layout_height="wrap_content"
android:text="@+string/tv_picking_content_second"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="left"
android:singleLine="false"
/>
</TableRow>
</TableLayout>
</RelativeLayout>
我用它在子弹列表中显示静态文本,所以我不打算在代码中动态创建项目符号+文本。如果有人有任何建议如何以更好的方式完成同样的事情,请取悦我。
顺便说一下,如果按照上面第二个链接中建议的解决方案:
android:text="<ol><li>item 1\n</li><li>item 2\n</li></ol>
子弹中跨越多行的第二行,第三行等不会与第一行相同,这非常难看。
答案 1 :(得分:5)
谢谢@Bjorn
你也可以做类似下面的事情。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/point"
android:textAppearance="?android:attr/textAppearanceSmall"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Your Text Here"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="14sp" />
</LinearLayout>
答案 2 :(得分:0)
我解决这个问题的方法是使用RelativeLayout和marginLeft。 marginLeft将在它与前一项之间留一个空白边距。
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbarTrackVertical="@drawable/scrollbar_vertical_track"
android:scrollbarThumbVertical="@drawable/scrollbar_vertical_thumb"
android:scrollbarSize="12dip">
<RelativeLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10sp">
<TextView
android:id="@+id/body_text3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:lineSpacingExtra="3sp"
android:text="Main paragraph of text, before the bulleted list"
android:textSize="15sp" />
<TextView
android:id="@+id/type1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:lineSpacingExtra="3sp"
android:text="• First bullet"
android:textSize="15sp"
android:layout_below="@+id/body_text3"
android:layout_marginLeft="25dp" />
<TextView
android:id="@+id/type2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:lineSpacingExtra="3sp"
android:text="• Second bullet"
android:textSize="15sp"
android:layout_below="@+id/type1"
android:layout_marginLeft="25dp" />
</RelativeLayout>
</ScrollView>
答案 3 :(得分:0)
试图指出问题的关键答案:
TableLayout
,每行包含两列。一列为TextView
的子弹,另一列为文本TextView
填充其余空TableRow
并缩进新行,将权重设置为1.您可以将项目符号权重设置为零,或者只是不设置项目符号权重并让它是空的示例:
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/bullet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/bullet"/>
<TextView
android:id="@+id/TextView01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="this is the text of a bullet list"/>
</TableRow>
</TableLayout>