【问题标题】:Forcing Android Fast Scroll Bar on ListViews to draw within padding强制 ListViews 上的 Android 快速滚动条在填充内绘制
【发布时间】:2013-08-02 17:56:56
【问题描述】:

我有兴趣创建一个由透明标题和在标题后面滚动的列表视图组成的屏幕。我有一个缺陷。 FAST 滚动条也绘制在标题下方。

由于某种原因,fastscrollbar 似乎不尊重应用于列表视图的滚动条样式。您会在下图中注意到正常滚动条工作正常,但 powerscroll 条位于透明标题后面。

不幸的是,我使用的列表视图通常有数百个项目,所以快速滚动条是必需的。有没有办法设置未记录的“fastscrollStyle”?我愿意接受任何建议!谢谢。

这是供参考的布局 XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">

    <ListView
        android:id="@+id/myListView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:clipToPadding="false"
        android:fastScrollEnabled="true"
        android:scrollbars="vertical"
        android:scrollbarStyle="insideOverlay"
        android:paddingTop="50dp"/>

    <TextView android:text="My Header"
              android:gravity="center"
              android:background="#8fff0000"
              android:layout_width="fill_parent"
              android:layout_height="50dp"/>
</RelativeLayout>

这个问题在 KitKat 中的 ListView 中得到了修复,但是 GridView 似乎仍然存在这个问题。谷歌?

【问题讨论】:

  • 使用线性布局而不是相对布局。顶部的标题,并在标题下设置列表视图位置。列表项也永远不会出现在标题和滚动条图标的后面。
  • 我希望列表视图项目绘制在标题后面,同时让快速滚动条尊重列表视图的垂直填充。 Linearlayout 没有快速滚动,如果您向其中添加数千个项目,性能将非常差。 :-)
  • 感谢此反馈。 ;)

标签: android android-layout android-listview


【解决方案1】:

最好的解决方案是将列表视图与其他布局分开,其中主要的 relativelayout 视图是父视图,其他布局是子视图。

EX.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">
     <RelativeLayout
              android:id"@+id/layoutHeader"
              android:layout_width="fill_parent"
              android:layout_height="50dp"
              android:layout_alignParentTop="true">

              <TextView android:text="My Header"
                        android:gravity="center"
                       android:background="#8fff0000"
                       android:layout_width="fill_parent"
                       android:layout_height="50dp"/>
    </RelativeLayout>

    <RelativeLayout
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_below="+id/layoutHeader">
    <ListView
        android:id="@+id/myListView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:clipToPadding="false"
        android:fastScrollEnabled="true"
        android:scrollbars="vertical"
        android:scrollbarStyle="insideOverlay"
        android:paddingTop="50dp"/>
    </RelativeLayout>
</RelativeLayout>

【讨论】:

  • 这不是简单地将列表视图绘制在标题前面,同时创建了不必要的更大的视图层次结构吗?
【解决方案2】:

此错误似乎已在 4.4 中修复。然而,在旧版本中,除了将填充保留为 0 之外,似乎没有已知的解决方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-13
    • 1970-01-01
    • 2017-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-02
    • 1970-01-01
    相关资源
    最近更新 更多