【问题标题】:Row in Android CustomAdapter showing not in full widthAndroid CustomAdapter 中的行显示不是全宽
【发布时间】:2014-06-10 02:55:28
【问题描述】:

我有以下问题: 我创建了一个 row.xml 文件以在我的 CustomAdapter 中使用。此行将是 ListView 的一部分。 这是一个xml文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/textUser"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Slashdot"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/time"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="right"/>
    </LinearLayout>

    <TextView
        android:id="@+id/messageText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

如果 TextView messageText 是几个字符而没有填满整行(比整行短),则该行不会显示为完整的可用宽度。它给我带来了几个问题:外观问题,当我尝试选择某行时出现问题,如果 messageText 只有几个字符长,我必须准确选择可用字符,而不仅仅是“单击”整行。

提前致谢

更新: 这些行看起来像这样:


用户 1 01:01:01 一些文字1


用户 2 01:01:01 一些文字2


代替:


用户 1 ---------------------------------------------- ----------------------------------------- 01:01:01 一些文字1


用户2---------------------------------------------- -------------------------------------------01:01:01 一些文字2


在第一种情况下,如果我想选择某行,我需要准确地“单击”“某些文本”。 我希望能够通过单击该行的任意位置来选择某行“单击”

【问题讨论】:

  • 你如何为你的列表视图设置点击监听器?
  • 你能发截图吗,XML没有明显的问题。
  • registerForContextMenu(myListView;
  • 我没有足够的“声誉”来发布图片..

标签: android listview row adapter


【解决方案1】:

将宽度分配给您的 TextView 的

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/textUser"
        android:layout_width="160dp"
        android:layout_height="wrap_content"
        android:text="Slashdot"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/time"
        android:layout_width="160dp"
        android:layout_height="wrap_content"

        android:gravity="right"/>
</LinearLayout>

<TextView
    android:id="@+id/messageText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

</LinearLayout>

【讨论】:

  • 我试过了,但我没有解决问题。另外,内部布局必须是水平的,因为我希望“textUser”和“time”在同一行。
  • 我可以做到,但我想根据设备将其设置为最大可用宽度,而不是固定大小
  • 你可以添加 layout-small、layout-large、layout-xlarge 文件夹,并在其中相应地修改宽度。
  • 听起来很合理。没有更通用的解决方案可用?
  • 可能有,但一般我用这种方法
猜你喜欢
  • 2021-07-28
  • 2021-05-30
  • 2021-12-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-14
  • 2010-09-26
相关资源
最近更新 更多