【问题标题】:scroll view collapse nested relative layouts proplemscrollview 折叠嵌套的相对布局问题
【发布时间】:2017-06-13 13:13:30
【问题描述】:

我有这个 xml:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical"
android:padding="8dp">


<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:id="@+id/layout_comands"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layoutDirection="ltr">

        <TextView
            android:id="@+id/textView_hfccomands"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_marginBottom="@dimen/activity_horizontal_margin"
            android:text="text " />

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_below="@id/textView_hfccomands"
            app:srcCompat="@drawable/ic_business_index" />

        <TextView
            android:id="@+id/textView_hfc_content"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/imageView"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_below="@id/textView_hfccomands"
            android:layout_toLeftOf="@id/imageView"
            android:layoutDirection="rtl"
            android:text="text " />


    </RelativeLayout>

    <View
        android:id="@+id/seprator1"
        android:layout_width="match_parent"
        android:layout_height="3dp"
        android:layout_below="@id/layout_comands"
        android:layout_marginTop="@dimen/main_screen_bottom_margings"
        android:background="@color/light_blue" />


    <RelativeLayout
        android:id="@+id/layout_lvExpMissions"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/seprator1"
        android:layout_marginTop="@dimen/main_screen_bottom_margings"
        android:background="@color/white">

        <ExpandableListView
            android:id="@+id/lvExphfc_my_missions"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </RelativeLayout>

    <View
        android:id="@+id/seprator2"
        android:layout_width="match_parent"
        android:layout_height="3dp"
        android:layout_below="@id/layout_lvExpMissions"
        android:background="@color/light_blue"></View>


    <RelativeLayout
        android:id="@+id/layout_button_help"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/seprator2"
        android:layout_marginTop="@dimen/main_screen_bottom_margings">

        <Button
            android:id="@+id/button_help"
            style="@style/button_custmoized"
            android:layout_width="match_parent"
            android:layout_height="60dp" />

    </RelativeLayout>

    <View
        android:id="@+id/seprator3"
        android:layout_width="match_parent"
        android:layout_height="3dp"
        android:layout_below="@id/layout_button_help"
        android:layout_marginTop="@dimen/main_screen_bottom_margings"
        android:background="@color/light_blue"></View>


    <RelativeLayout
        android:id="@+id/layot_emergency_reports"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/seprator3"
        android:layout_marginTop="@dimen/main_screen_bottom_margings"
        android:background="@color/white">

        <ListView
            android:id="@+id/listView_emergencyReports"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </RelativeLayout>

    <View
        android:id="@+id/seprator4"
        android:layout_width="match_parent"
        android:layout_height="8dp"
        android:layout_below="@id/layot_emergency_reports"
        android:layout_marginTop="@dimen/main_screen_bottom_margings"
        android:background="@color/light_blue"></View>

</RelativeLayout>

问题是我的滚动视图以某种方式包装内容并表现得很奇怪! 我只想能够向下滚动整个内容 但是滚动视图将相对布局推到屏幕顶部! 我在这里错过了什么

【问题讨论】:

  • 行为怪异?添加一些截图
  • 是否需要相对布局?尝试使用线性布局。
  • 当我用 relativelayout 替换父滚动视图时,您可以在第二张图片中看到
  • @SurendraShrestha 我试过 Linear Lyout 它没有帮助,它隐藏了视图
  • 我认为问题在于您在列表视图中有一个列表视图。因此,在尝试滚动列表内的列表时,仅滚动内部列表而不滚动外部列表。这似乎是你的问题。

标签: java android xml scrollview


【解决方案1】:

将此代码添加到您在 xml 中的相对布局中

android:focusableInTouchMode="true"

android:visibility="visible"

试试这个

【讨论】:

  • 这根本不相关
【解决方案2】:

将此属性添加到xml中的ScrollView

android:fillViewport="true"

它会解决问题。

【讨论】:

  • 视图是否适合设备上的整个屏幕?如果是,请尝试在屏幕尺寸较小的设备上运行它。
  • 没有视图适合整个屏幕,如上图所示,我可以滚动列表视图,但我希望能够在向下滚动时滚动整个视图
  • 使用 NestedScrollView 代替 ScrollView
  • 嵌套滚动 ivew 没有解决我的问题 .. 我在这里遗漏了什么是什么?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-17
  • 2010-12-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多