首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >列表视图中的滚动条

列表视图中的滚动条
EN

Stack Overflow用户
提问于 2013-09-04 05:27:41
回答 4查看 771关注 0票数 0

为什么在列表视图中有一个滚动条,即使它中显示的数据不需要滚动?这是我的xml文件

代码语言:javascript
运行
复制
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:background="@drawable/background"
     android:orientation="vertical" >

   <ListView
      android:id="@+id/listview"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:divider="@null"
      android:dividerHeight="0dip" />

   <TextView
      android:id="@+id/empty"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:gravity="center"
      android:text="@string/no_result_text"
      android:visibility="gone" />

</LinearLayout>
EN

回答 4

Stack Overflow用户

发布于 2013-09-04 05:32:55

getLastVisiblePosition()与可运行的getCount()进行比较,您将了解列表视图是否适合屏幕。还检查最后一个可见行是否完全符合屏幕。

代码语言:javascript
运行
复制
ListView listView;
Runnable fitsOnScreen = new Runnable() {
    @Override
    public void run() {
        int last = listView.getLastVisiblePosition();
        if(last == listView.getCount() - 1 && listView.getChildAt(last).getBottom() <= listView.getHeight()) {
           listView.setScrollContainer(false);
        }
        else {
            listView.setScrollContainer(true);
        }
    }
};

最后,在ListView的Handler中: onCreate()

代码语言:javascript
运行
复制
listView.post(fitsOnScreen);
票数 0
EN

Stack Overflow用户

发布于 2013-09-04 05:36:48

你可以通过

代码语言:javascript
运行
复制
listView.setScrollContainer(false);

欲了解更多信息,请查看

How to get a non scrollable ListView?

票数 0
EN

Stack Overflow用户

发布于 2013-09-04 05:37:48

如果您不想永远隐藏滚动条。那它会帮你的。由于android:layout_height=的原因,listView和TextView上出现了“match_parent”滚动条。

代码语言:javascript
运行
复制
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:background="@drawable/background"
     android:orientation="vertical" >

     <ListView
        android:id="@+id/listview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" // change 1
        android:divider="@null"
        android:dividerHeight="0dip" />

     <TextView
        android:id="@+id/empty"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" //change 2
        android:gravity="center"
        android:text="@string/no_result_text"
        android:visibility="gone" />

 </LinearLayout>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18605995

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档