【问题标题】:Android Form Scrolling with Translucent Status Bar带有半透明状态栏的 Android 表单滚动
【发布时间】:2014-11-06 08:43:04
【问题描述】:

我的目标是 SDK 21,Min SDK 15,在 API 19 设备上测试 (Android 4.4.4)

我的活动中有此代码

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_launcher);

    setTranslucentStatus();

}

@TargetApi(Build.VERSION_CODES.KITKAT)
private void setTranslucentStatus() {
    getWindow()
            .addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}

它有效,但有一个问题。在布局中,我有一个 ScrollView。 ScrollView 不滚动。但是,如果我注释掉对 setTranslucentStatus() 的调用,滚动就可以了。

顺便说一下,主题是NoActionBar

关于为什么当状态栏是半透明时 ScrollView 会拒绝滚动的任何线索?

【问题讨论】:

  • 这里有同样烦人的问题,在 Lollipop 中,在我的 v21/styles.xml 中设置 Theme.Material.Light.NoActionBar.TranslucentDecor 时,我无法让 ScrollView 工作。尝试设置filViewPort和AdjustResize参数,都不行。
  • 这里有同样的问题。你找到解决办法了吗?
  • 也有同样的问题。

标签: android statusbar


【解决方案1】:

我不知道你是否已经找到了解决方案,但如果你使用 ConstraintLayout 应该可以解决这个烦人的错误。

示例布局如下所示

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<ScrollView
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </LinearLayout>

</ScrollView>

【讨论】:

    【解决方案2】:

    只需使用滚动视图的属性 -- scrollbars: none in scroll view 它使滚动视图在没有滚动条的情况下滚动 不需要半透明标志,只需将其删除即可

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-07
      • 1970-01-01
      • 2017-12-24
      • 2017-07-07
      • 2015-04-01
      • 2012-10-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多