【问题标题】:Scrolling in RelativeLayout在相对布局中滚动
【发布时间】:2017-02-20 19:53:15
【问题描述】:

我在RelativeLayout 中有textview 和listview。滚动列表视图时如何滚动此文本视图?当我滚动列表视图时,我希望 textview 不会从顶部挂出

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="top"
    android:padding="10dp"
    android:paddingBottom="0dp"
    android:id="@+id/info_presents_surveys"
    android:text="@string/info_presents_surveys"
    android:textColor="@color/empty_color"
    android:background="@color/color_gray"/>

<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/refresh"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/info_presents_surveys">

    <ListView
        android:id="@+id/list_view_surveys"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="@color/members_speakers.divider"
        android:dividerHeight="1dp" />
</android.support.v4.widget.SwipeRefreshLayout>

【问题讨论】:

  • 您是否也想让 textview 向上滚动?如果是这样,请将所有内容放在 Scroll 或 RecyclerView 中。
  • RecyclerView是怎么做到的?
  • 研究的魔力!这就是软件开发的重点和乐趣所在。学习!如果我确切地告诉你如何做到这一点,你将永远学不会。从字面上将 RecyclerView 粘贴到谷歌,我保证你会找到大量的资源。

标签: java android listview scroll textview


【解决方案1】:

TextView 不在滚动组件内,它在不滚动的父布局 RelativeLayout 内。

为了让它滚动,你必须把它放在ScrollView(或类似的滚动组件)中。

应该是这样的:

<ScrollView>
    <RelativeLayout>
        <TextView>
        <SwipeRefreshLayout>
             <ListView/>
        </SwipeRefreshLayout>
    </RelativeLayout>
</ScrollView>

【讨论】:

  • 在谷歌中输入“ScrollViewtutorial”,它会告诉你怎么做。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-11
相关资源
最近更新 更多