【问题标题】:Scrollview getting blocked by linear layout滚动视图被线性布局阻塞
【发布时间】:2017-11-13 03:06:49
【问题描述】:

我有这样的设计: XMLFile1.xml

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/option_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

  <ScrollView
    android:name="question_paper_scrollView"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true">

    <FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/fragment_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>
  </ScrollView>
</RelativeLayout>

XMLFile2.xml

<RelativeLayout 
 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="fill_parent"
 android:layout_height="match_parent">
  <include layout=XMLFile1.xml>
  <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:gravity="center|bottom"
    android:weightSum="4"/>
 </RelativeLayout>

我已根据thisScrollView 中设置android:fillViewport="true",并根据this 设置FrameLayoutminimumHeight()FrameLayout 包含测验问题,它们需要可滚动,LinearLayout 包含一组按钮,例如下一个、上一个和清除。我从this 了解到LinearLayout 可以隐藏ScrollView 但我可以看到滚动条。实现的正确方法是什么:给定设计的可滚动问题? PS:我只能使用LinearLayout,因为我想在屏幕底部设置一组按钮,而使用FrameLayout,因为我从数据库中动态加载测验问题。

解决方案:两个答案的结合。在所有布局中使用 wrap_content,在线性布局中使用用户 layout_below 属性

【问题讨论】:

  • 显示布局的属性。
  • @Dabiuteef 添加属性
  • 我想这可能会起作用:将 LinearLayout 的 android:layout_height 更改为 wrap_content,并将 android:layout_above="" 添加到 include 标记中。
  • 在两个 xml 文件中设置高度为 wrap_content
  • 我必须只为最外层的标签还是所有标签?对于所有标签,它没有帮助,因为 LineaarLayout 包含功能有点像底部标签的按钮

标签: android android-layout scrollview android-scrollview


【解决方案1】:

您可以为 ScrollView 调用 bringToFront() 如果它不阻止视图。 或调整android:height 的浏览量。 您还将 ScrollView 设置为 android:layout_below="@id/includeView"

【讨论】:

  • 当我这样做时,我的框架布局完全隐藏了
  • 所以正如我所说,您应该更改视图高度并设置 layout_below
【解决方案2】:

试试这个,在 xml 文件中使用所有布局和视图的高度 wrap_content 而不是 fill_parent 或 match_parent。

【讨论】:

  • LinearLayout 适用于类似于底部标签的按钮。单击下一步时,我将一个新问题加载到框架中。当我将 LinearLayout 的高度设置为 wrap_content 时,所有按钮都会上升。此外,滚动视图仅在按钮之前有效,并且不会超出以显示按钮下方的文本
  • 线性布局的方向是什么?
  • 水平方向。如果我将其更改为垂直,则按钮将堆叠在其他按钮之上。我在下面的底部标签按钮中使用了线性布局:stackoverflow.com/questions/18944692/…
  • 在 xmlfile2 中给出一些固定高度的线性布局并给出 android:layout_alignParentBottom="true" 并删除 android:gravity="center|bottom"
  • 抱歉,这样做所有按钮都会显示在屏幕顶部
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-09
  • 1970-01-01
相关资源
最近更新 更多