【问题标题】:Using a ScrollView on RelativeLayout that contains an ExpandableListView在包含 ExpandableListView 的 RelativeLayout 上使用 ScrollView
【发布时间】:2011-12-06 20:37:57
【问题描述】:

我有这个RelativeLayout 我正在使用:

<?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <Button
            android:layout_width="wrap_content"
            android:id="@+id/screen_team_enableproximity"
            android:text="Enable proximity"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/screen_team_checkboxproximity"
            android:layout_alignBottom="@+id/screen_team_checkboxproximity"
            android:layout_alignParentLeft="true"
            android:layout_toLeftOf="@+id/screen_team_checkboxproximity"></Button>
        <CheckBox
            android:layout_width="wrap_content"
            android:id="@+id/screen_team_checkboxproximity"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true"
            android:clickable="false"></CheckBox>
        <ExpandableListView
            android:layout_width="match_parent"
            android:id="@+id/screen_team_teamslist"
            android:layout_height="match_parent"
            android:layout_below="@+id/screen_team_availableteams"
            android:layout_centerHorizontal="true"></ExpandableListView>
        <TextView
            android:layout_width="wrap_content"
            android:id="@+id/screen_team_availableteams"
            android:text="Available Teams"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:layout_below="@+id/screen_team_getallteams"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="10dp"></TextView>
        <Button
            android:text="Create Team"
            android:id="@+id/screen_team_createteam"
            android:layout_height="wrap_content"
            android:layout_below="@+id/screen_team_enableproximity"
            android:layout_width="match_parent"
            android:layout_marginTop="65dip"></Button>
        <Button
            android:text="Delete Team"
            android:id="@+id/screen_team_deleteteam"
            android:layout_height="wrap_content"
            android:layout_below="@+id/screen_team_createteam"
            android:layout_centerHorizontal="true"
            android:layout_width="match_parent"></Button>
        <Button
            android:layout_width="match_parent"
            android:text="Get available teams"
            android:id="@+id/screen_team_getallteams"
            android:layout_height="wrap_content"
            android:layout_below="@+id/screen_team_deleteteam"
            android:layout_alignParentLeft="true"></Button>
    </RelativeLayout>

问题是我希望它在 ScrollView 或类似的内部使用 - 整个布局不适合屏幕,尤其是当您向 ExpandableListView 添加多个组时。

我尝试将RelativeLayout 放入ScrollView,但它根本不起作用。

如何设置包含RelativeLayout 的滚动屏幕?

【问题讨论】:

    标签: android scrollview android-relativelayout expandablelistview


    【解决方案1】:

    将可展开的listView上方的所有视图作为listView header,将所有低于listView的视图作为listView footer。然后你就为所有东西启用了滚动。

    【讨论】:

    • listview页眉和页脚是什么意思?
    【解决方案2】:

    这是一个棘手的问题。这里有几个关于如何使用 ScrollView 和 ListView 的讨论。看看这个问题:Scrolling with Multiple ListViews for Android。这个想法是只有一个列表(创建一个自定义适配器)并在您的可扩展列表之前和之后添加页眉和页脚。

    【讨论】:

      【解决方案3】:

      除了页眉/页脚方法之外,如果您将在 expandableList 之前定义所有视图并为其提供相对位置(layout_above/layout_below),您将获得所需的视图。

      【讨论】:

        猜你喜欢
        • 2014-06-14
        • 2012-10-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-03-26
        • 1970-01-01
        • 2018-09-28
        • 2013-05-28
        相关资源
        最近更新 更多