【问题标题】:Setting the View visibility to View.GONE, makes it invisible, still takes up space将视图可见性设置为 View.GONE,使其不可见,仍然占用空间
【发布时间】:2018-03-29 11:48:54
【问题描述】:

我有一个想要折叠的视图,所以我将可见性设置为 View.GONE,视图变得不可见,但它仍然占用空间。

我不知道它可能是什么,有人有想法吗?

这是之前的图像(视图 D):

这是(视图 D)之后的图像:

这是布局:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/mainColor"
android:clipToPadding="false"
android:fillViewport="false"
android:scrollbars="none">

<android.support.constraint.ConstraintLayout
    android:id="@+id/options_panel"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:descendantFocusability="beforeDescendants"
    android:focusableInTouchMode="true">

    <!-- other irrelevants views -->

    <TextView
        android:id="@+id/time_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="32dp"
        android:fontFamily="sans-serif"
        android:text="@string/toolbar_options_title_time"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/option_hexa_sorting" />

    <com.development.mekanius.bounce.customElements.HexaRadioGroupView
        android:id="@+id/option_hexa_time"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/time_title" />

    <Button
        android:id="@+id/option_create_post"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="32dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="32dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/option_hexa_time" />

</android.support.constraint.ConstraintLayout>

提前致谢

【问题讨论】:

  • 您要隐藏哪个视图? XML 中并不清楚。
  • 您查看 GONE 或 INVISIBLE 了吗?
  • 对不起。我试图隐藏的视图是 option_hexa_time,我正在使用 View.GONE
  • 我已经尝试将视图包装在 LinearLayout 中,但它并没有改变任何东西。

标签: android android-layout android-constraintlayout


【解决方案1】:

首先,很抱歉回复晚了,但是我一直卡在决赛中,没有太多时间。

好的,问题完全是另外一回事。
我正在使用 Spotify 的 Mobius 作为状态机:
https://github.com/spotify/mobius

它使用后台线程来消耗效果,因此对 UI 进行操作会产生错误。但由于某种原因,错误被抑制了(不在日志中,也没有引发异常),所以我看到的只是视图不服从命令。

我得出了这个结论,删除代码行直到某些东西起作用。
很老的时尚。

感谢所有试图提供帮助的人。

【讨论】:

    【解决方案2】:

    我花了几个小时调试为什么会发生这种情况并偶然发现了您的答案。我正在改变一个 Rx-Java 线程的可见性,该线程应该在主线程上运行,但显然不是!做一个 view.post {..} 为我解决了这个问题!非常感谢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-24
      • 1970-01-01
      • 2013-09-13
      • 1970-01-01
      • 2018-11-26
      • 1970-01-01
      • 2019-08-02
      • 1970-01-01
      相关资源
      最近更新 更多