【问题标题】:fitsSystemWindows and extra padding on kitkatfitSystemWindows 和 kitkat 上的额外填充
【发布时间】:2014-06-05 11:31:19
【问题描述】:

我在一个带有如下操作栏的 Activity 中有一个 ListView:

<LinearLayout
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    tools:context=".LauncherActivity"

    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
        <ListView
            android:id="@+id/lvcalendar"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:clipToPadding="false"
            android:fitsSystemWindows="true"


            android:dividerHeight="10dp"
            android:paddingTop="10dp"
            android:paddingBottom="10dp"
            android:divider="#00ffffff"

            android:scrollbarThumbVertical="@drawable/scrollbarstyle"
            android:layout_gravity="top"
            android:listSelector="@android:color/transparent"
            />
</LinearLayout>

活动主题有:

<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>

在 Kitkat 设备下,行为是我想要的:项目在底部和顶部有 10dp 的填充。在 kitkat 设备上,paddingTop 和 paddingBottom 似乎没有效果,因为 ListView 的项目在顶部和底部没有 10dp 填充。

我认为问题出在android:fitsSystemWindows 的某个地方,因为由于半透明的装饰,该属性似乎为视图设置了必要的填充,并使android:padding* 属性被忽略。

我的问题:无论如何我可以将android:fitsSystemWindows 设置为true 并仍然在视图上添加额外的填充?

【问题讨论】:

  • 请检查答案是否已接受! ,怎么了?
  • 我想要的行为不是@Spirit所说的。
  • 您找到解决方案了吗?遇到同样的问题
  • 没有。我实际上在这里忘记了这个问题。我是这个问题的所有者,我不允许对我测试过的不起作用的解决方案投反对票?这个stackoverflow就是那样没用。无论如何,其他人只是对不是解决方案的事情投了赞成票。不过,分享问题和答案的地方毫无用处。

标签: android android-4.4-kitkat translucentdecor


【解决方案1】:

您应该将此属性添加到父视图:

<LinearLayout
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
tools:context=".LauncherActivity"
android:fitsSystemWindows="true"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

【讨论】:

  • 如果将此添加到父活动,列表视图将不会填充导航栏。我仍然希望在半透明导航栏后面有列表视图,但我希望有额外的填充加上 fitSystemWindows 的填充。这可能是不可能的,我不知道。如果您需要更多信息或屏幕截图,请说。谢谢
【解决方案2】:

您可以创建自己的类来扩展 ListView 并覆盖该类中的 fitSystemWindows(),以便将插入添加到现有填充(默认实现用插入替换任何填充)。然后你不需要在布局 XML 中指定 android:fitsSystemWindows 属性,因为你的新实现总是会被调用。

【讨论】:

  • 看来这就是我需要的。我会尽快尝试,我会在这里告诉结果和解决方案。谢谢!
【解决方案3】:

答案是否定的。如果您将 android:fitsSystemWindows 设置为 true,它会覆盖该视图的填充。

您可以通过拥有两个嵌套视图来实现您想要的行为,其中父视图的 android:fitsSystemWindows 为 true,而其他视图包含填充。

【讨论】:

    【解决方案4】:

    移动你的 android:fitsSystemWindows="true" 到你的父 ListView

    【讨论】:

      【解决方案5】:

      使用时:

      fitsSystemWindows=true
      

      对于布局,内边距将被重置为插图。您可以使用FitsSystemWindowsFrameLayout 来解决此默认行为。

      【讨论】:

      • 始终欢迎提供指向潜在解决方案的链接,但请add context around the link,以便您的其他用户知道它是什么以及为什么存在。始终引用重要链接中最相关的部分,以防目标站点无法访问或永久离线。考虑到仅仅是指向外部站点的链接Why and how are some answers deleted? 的一个可能原因。
      猜你喜欢
      • 2016-07-24
      • 2013-09-05
      • 2018-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-21
      • 1970-01-01
      相关资源
      最近更新 更多