【发布时间】:2017-08-15 20:43:54
【问题描述】:
我在标题下方使用Spinner (TextView)。它最初设置为View.GONE,当点击标题时,Spinner 设置为View.VISIBLE,并且在标题下方使用performClick() 显示弹出窗口,这正是我想要的。
但是当Spinner 仍然是VISIBLE 时,我会异步更新BaseAdapter 以向Spinner 添加更多项目。更新后,Spinner 向上移动并覆盖在标题上。我该如何解决这个问题?
我使用过android:dropDownVerticalOffset,但更新后显示相同的行为。
我的布局:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/some_other_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
<android.support.v7.widget.AppCompatSpinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:background="@null"
android:overlapAnchor="true"
android:spinnerMode="dropdown"
android:visibility="gone"></android.support.v7.widget.AppCompatSpinner>
</FrameLayout>
</LinearLayout>
【问题讨论】:
-
你能把你的整个布局放上去吗?
-
添加了完整的布局
-
尝试使用 View.Invisible 而不是 View.Gone,因为它会占用空间。这将帮助您解决重叠问题;)
-
它显示与 View.INVISIBLE 相同的行为。只有在添加更多项目以适应可见屏幕时,才会发生这种情况。
-
不幸的是,我现在无法测试,我没有正确的 IDE atm,但您可以尝试让微调器可见,看看它第一次创建的位置,以确保它位于正确的位置,因为我可以看到框架布局内的错误有一个额外的线性布局,基本上什么都不做。