【问题标题】:Android - adding scroll view and fixed footer in scroll view with scrollable footer contentAndroid - 在带有可滚动页脚内容的滚动视图中添加滚动视图和固定页脚
【发布时间】:2014-04-07 16:33:55
【问题描述】:

我正在做一个 UI 设计,我必须设计一个完全可滚动的视图。在这个视图中,我在底部有一个视图寻呼机和一个固定的页脚,但是当用户在垂直方向滚动内容时,这个页脚也会滚动。现在这里的页脚有很长的描述,但如果不滚动,那是不可见的。在水平方向滚动时,视图寻呼机将工作并且页脚似乎固定在底部。
这是我的代码。

 <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:fillViewport="true" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <LinearLayout
                android:id="@+id/linearLayoutFooter"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_margin="12dp"
                android:orientation="vertical" >

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="12dp"
                    android:orientation="horizontal"
                    android:weightSum="100" >

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="80"
                        android:text="some dummy textl and Prevention"
                        android:textSize="12dp" />

                    <ImageView
                        android:id="@+id/imageviewViewExpander"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical|center_horizontal"
                        android:layout_weight="20"
                        android:src="@drawable/page_circle_arrow_down" />
                </LinearLayout>

                <TextView
                    android:id="@+id/textveiw"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="15dp"
                    android:text="some dummy textsome dummy textsome dummy textsome dummy text\nsome dummy textsome dummy textsome dummy textsome dummy textsome dummy textsome dummy text\nsome dummy textsome dummy textsome dummy textsome dummy textsome dummy text\nsome dummy textsome dummy textsome dummy textsome dummy text" >
                </TextView>
            </LinearLayout>

            <android.support.v4.view.ViewPager
                android:id="@+id/pager"
                android:layout_width="match_parent"
                android:layout_height="fill_parent"
                android:layout_above="@id/linearLayoutFooter"
                android:layout_alignParentTop="true" >
            </android.support.v4.view.ViewPager>
        </RelativeLayout>
    </ScrollView>

这里的问题是我必须让页脚粘在底部,除非用户滚动,甚至视图寻呼机内容不可见。

【问题讨论】:

  • 所以您需要将页脚固定在底部,还是滚动视图上的最后一项,提供图像以便更好地说明。
  • 如果用户不垂直滚动视图,页脚将保持在底部。一旦他这样做,页脚也会向上移动,但如果他在水平方向滚动,则视图寻呼机将工作以更改内容并且页脚将保持在原位。
  • 问题是不向下滚动就看不到页脚?
  • 页脚不可见,但下面有一些内容只有在用户滚动视图时才可见。

标签: android android-viewpager scrollview


【解决方案1】:

我认为您可以将scrollview 放在RelativeLayout 之后和LinearLayout 之前 像这样:

 <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >
<!--here-->
<ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:fillViewport="true" >

            <LinearLayout
                android:id="@+id/linearLayoutFooter"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_margin="12dp"
                android:orientation="vertical" >

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="12dp"
                    android:orientation="horizontal"
                    android:weightSum="100" >

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="80"
                        android:text="Content courtesy of Centers for Disease Control and Prevention"
                        android:textSize="12dp" />

                    <ImageView
                        android:id="@+id/imageviewViewExpander"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical|center_horizontal"
                        android:layout_weight="20"
                        android:src="@drawable/page_circle_arrow_down" />
                </LinearLayout>

                <TextView
                    android:id="@+id/textViewDiseaseControl"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="15dp"
                    android:text="To help recognize a concussion, you should watch for and ask others to report the following two things among your athletes:\n\nA forceful bump, blow, or jolt to the head or body that results in rapid movement of the head.\n\nAny concussion signs or symptoms, such as a change in the athlete&apos;s behavior, thinking, or physical functioning.\n\nKeep this list of signs and symptoms on hand. Athletes who exhibit or report one or more of the signs and symptoms listed below, or simply say they just &quot;don&apos;t feel right&quot; after a bump, blow, or jolt to the head or body, may have a concussion." >
                </TextView>
            </LinearLayout>
 </ScrollView><!--here-->
            <android.support.v4.view.ViewPager
                android:id="@+id/pager"
                android:layout_width="match_parent"
                android:layout_height="fill_parent"
                android:layout_above="@id/linearLayoutFooter"
                android:layout_alignParentTop="true" >
            </android.support.v4.view.ViewPager>
        </RelativeLayout>

【讨论】:

  • 如果我将视图寻呼机放在滚动视图之外,则它不起作用,即使它工作,如果视图寻呼机在滚动视图之外,也将无法滚动。
【解决方案2】:

只为需要滚动的组件提供滚动视图。将其他内容保留在滚动视图之外。您可以使用

等属性将页脚保留在活动的底部

android:alignParentBottom="true"

【讨论】:

  • 我需要在滚动视图中保留页脚。
猜你喜欢
  • 1970-01-01
  • 2011-05-03
  • 1970-01-01
  • 2012-10-27
  • 1970-01-01
  • 2013-02-04
  • 1970-01-01
  • 2022-01-09
  • 1970-01-01
相关资源
最近更新 更多