Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Listview格式文本_Android - Fatal编程技术网

Android Listview格式文本

Android Listview格式文本,android,Android,是否可以在Listview中格式化项目文本,使其看起来像这样: 字符串的一部分为粗体,另一部分为非粗体 谢谢是的,您只需要有两个不同的文本视图,一个用于粗体文本,另一个用于未绑定文本。因此,每行的布局如下所示: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_widt

是否可以在Listview中格式化项目文本,使其看起来像这样:

字符串的一部分为粗体,另一部分为非粗体


谢谢

是的,您只需要有两个不同的文本视图,一个用于粗体文本,另一个用于未绑定文本。因此,每行的布局如下所示:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="horizontal"
>
   <TextView android:id="@+id/bold_field"
     android:layout_width="wrap_content"
     android:layout_height="fill_parent"
     android:textStyle="bold"
   />
   <TextView android:id="@+id/non_bold_field"
     android:layout_width="wrap_content"
     android:layout_height="fill_parent"
   />
</LinearLayout>


然后,您将使用映射将字符串的适当部分映射到每个TextView。如果你想让字符串看起来天衣无缝,你可能需要处理文本视图的样式。

是的,你只需要有两个不同的文本视图,一个用于粗体文本,一个用于未绑定文本。因此,每行的布局如下所示:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="horizontal"
>
   <TextView android:id="@+id/bold_field"
     android:layout_width="wrap_content"
     android:layout_height="fill_parent"
     android:textStyle="bold"
   />
   <TextView android:id="@+id/non_bold_field"
     android:layout_width="wrap_content"
     android:layout_height="fill_parent"
   />
</LinearLayout>


然后,您将使用映射将字符串的适当部分映射到每个TextView。如果你想让字符串看起来天衣无缝,你可能需要修改文本视图的格式。

这里有一个格式化字符串的方法

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="part_bold"><b>%1$s</b> %2$s</string>
</resources>

Resources res = getResources();
String part_bold_text = String.format(res.getString(R.string.part_bold), bold_string, normal_string);

%1$s%2$s
Resources res=getResources();
String part_bold_text=String.format(res.getString(R.String.part_bold)、bold_String、normal_String);
xml中的字符串有两个参数,一个是粗体参数,另一个是普通参数。使用此选项可以获取部分粗体和部分法线的字符串(
部分粗体文本


HTH.

这里有一个格式化字符串的方法

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="part_bold"><b>%1$s</b> %2$s</string>
</resources>

Resources res = getResources();
String part_bold_text = String.format(res.getString(R.string.part_bold), bold_string, normal_string);

%1$s%2$s
Resources res=getResources();
String part_bold_text=String.format(res.getString(R.String.part_bold)、bold_String、normal_String);
xml中的字符串有两个参数,一个是粗体参数,另一个是普通参数。使用此选项可以获取部分粗体和部分法线的字符串(
部分粗体文本


HTH.

您使用的是标准适配器还是自定义列表视图适配器?您使用的是标准适配器还是自定义列表视图适配器?但这不是假设字符串是静态的,并且在xml资源文件中?这不起作用。当我将此字符串放入ListViews时,格式设置是正常的。但是,这不是假设字符串是静态的,并且位于xml资源文件中吗?这不起作用。当我将此字符串放入ListView时,格式是正常的,但是。。。也许我应该试试。我喜欢ListView,但这似乎是唯一的方法。想想看,情况并没有那么糟。:)好吧,我不想浪费时间尝试它,然后发现我不能使用它,因为“某物”;)所以可以肯定的是,它创建了一些类似于HTML表格的布局。每一个文本视图都像每一个?希望它不是那么复杂:)但是。。。也许我应该试试。我喜欢ListView,但这似乎是唯一的方法。想想看,情况并没有那么糟。:)好吧,我不想浪费时间尝试它,然后发现我不能使用它,因为“某物”;)所以可以肯定的是,它创建了一些类似于HTML表格的布局。每一个文本视图都像每一个?希望不是那么复杂:)