【问题标题】:Android ListView: Empty space on first item in the listAndroid ListView:列表中第一项的空白
【发布时间】:2013-03-12 06:04:20
【问题描述】:

我正在使用带有自定义适配器的 ListView - 每行包含 2 个 TextView;水平对齐。我面临的问题:第一行项目顶部出现空白区域;它仍然存在,因为行视图被回收。这是我的布局 XML 中的 sn-p。

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1.0">

    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:dividerHeight="0.0dp"
        android:divider="@color/transparent"
        android:cacheColorHint="@color/transparent"
        android:listSelector="@color/transparent"
        android:scrollbars="none"/>

    <View
        android:layout_width="fill_parent"
        android:layout_height="10dp"
        android:background="@drawable/shadow_bottom"
        android:layout_alignParentBottom="true"/>
</RelativeLayout>

这是行项目布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content">
   <MyTextView1
       android:id="@+id/text"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:text="Sample text"
       android:paddingLeft="20dp"
       android:paddingRight="10dp"/>
   <MyTextView2
       android:id="@+id/number"
       android:layout_width="15dp"
       android:layout_height="wrap_content"
       android:gravity="right"
       android:paddingLeft="2dp"
       android:paddingRight="3dp"
       android:textSize="11sp"
       android:text="num"
       android:background="@color/transparent"
       android:textColor="@color/number_dark" />
</RelativeLayout>

MyTextView1 是一个自定义文本视图,用于保存 unicode 文本(马拉雅拉姆语)

这是一个屏幕截图:http://i.imm.io/Z3CH.png 可以看到空白区域是浅灰色的(也就是布局的背景色)

当我滚动时,当第一行被回收时,空白空间仍然存在-http://i.imm.io/Z3Dd.png

我怎样才能删除这个空白空间?

【问题讨论】:

  • 为什么你的 xml 中有 view?尝试删除它并告诉我空白空间是否仍然存在
  • “视图”是在底部应用阴影。我尝试删除它。甚至去掉了RelativeLayout,直接给ListView设置权重——还是会出现空白。
  • 今晚我将尝试调试您的代码以找出解决方案,因为我正在工作:)

标签: android listview unicode


【解决方案1】:

从您的textview 中删除左填充。
希望这会有所帮助

【讨论】:

  • 我试过了 - 没有帮助。删除左侧填充只是导致我的 2 个文本视图重叠。我提到的问题中的空白区域出现在第一行的顶部。我尝试将 marginTop 和 paddingTop 显式设置为零 - 这也不起作用。
  • 您是否尝试过像 margintop=-2dp 这样的负值。我知道这不是一件好事。但仅用于测试目的。
  • 是的,我也试过负 marginTop。那并没有解决问题-另外,这影响了所有行:(
  • 不,水平对齐。文本出现在数字旁边。查看屏幕截图。
猜你喜欢
  • 2013-01-08
  • 1970-01-01
  • 2013-12-10
  • 1970-01-01
  • 1970-01-01
  • 2015-05-03
  • 2011-10-06
  • 1970-01-01
  • 2021-02-13
相关资源
最近更新 更多