【问题标题】:How can I prevent the truncation of a listview by the layout header?如何防止布局标题截断列表视图?
【发布时间】:2020-03-08 21:54:47
【问题描述】:

我看不到列表视图的第一行。我假设屏幕页面的标题与列表视图重叠。

我的片段文件如下:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="?attr/layout_background_color">

<LinearLayout
    android:id="@+id/colors_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:visibility="visible">

    <ListView
        android:id="@+id/colors_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

</android.support.v4.widget.NestedScrollView>

任何建议都会很有帮助。

编辑:我在下面包含我的活动文件。

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/coordinator_layout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".views.activities.ColorActivity">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<fragment
    android:id="@+id/color_fragment"
    android:name="com.microsoft.skype.teams.views.fragments.ColorFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

</android.support.constraint.ConstraintLayout>

作为 hack,我目前正在添加额外的一行数据。添加额外的数据行显然是我希望避免的。

【问题讨论】:

  • 您是否在列表视图上方添加了工具栏?
  • 如果这确实是Fragment 的布局,那么问题很可能主要在于Activity 布局。
  • 在您的活动布局中,将FrameLayout 放在您的工具栏下方。
  • 这是由于工具栏的原因,在下面查看我的答案,看看你是否能得到你想要的。
  • 该布局中的内部元素表明您的意思是使用&lt;CoordinatorLayout&gt; 作为根,而不是&lt;ConstraintLayout&gt;。如果您更改为&lt;CoordinatorLayout&gt;,则&lt;fragment&gt; 上的layout_behavior 将使其自动布置在&lt;AppBarLayout&gt; 下方。

标签: android listview user-interface


【解决方案1】:

问题是您的工具栏占用了第一行的高度。要摆脱这种情况,请执行以下操作:

    <?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="?attr/layout_background_color">

    <LinearLayout
        android:id="@+id/colors_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="?attr/actionBarSize"  // added this line now your
        android:orientation="vertical"                     listview will start below
        android:visibility="visible">                      toolbar

        <ListView
            android:id="@+id/colors_list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </LinearLayout>

</android.support.v4.widget.NestedScrollView>

【讨论】:

  • 乐于助人。 :)
猜你喜欢
  • 2013-08-20
  • 1970-01-01
  • 2023-04-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多