在包含 ExpandableListView 的relativelayout上使用scrollview
我正在使用这个 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
的滚动屏幕?
I've got this RelativeLayout
I am using:
<?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>
The problem is I want to it to be used inside a ScrollView
or similiar - the entire layout does not fit on the screen, especially when you add several groups to the ExpandableListView
.
I've tried putting the RelativeLayout
inside a ScrollView
, but it dosn't work at all.
How do I setup a scrolling screen with my RelativeLayout
in it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将可展开的 listView 上方的所有视图作为 listView header ,将下方的所有视图作为 listView footer 。然后你就可以对所有内容启用滚动了。
Put all the views above the expandable listView as listView header , and all the views below as listView footer. Then you have scrolling enabled for everything.
这是一个棘手的问题。这里有一些关于如何将 ScrollView 与 ListView 一起使用的讨论。看看这个问题:Scrolling with Multiple ListViews for Android。这个想法是只有一个列表(创建一个自定义适配器)并在可扩展列表之前和之后添加页眉和页脚。
This is a tricky one. There were several discussion here on SO on how to use ScrollView with ListView. Have a look at this question: Scrolling with Multiple ListViews for Android. The idea is to have only one list (create a custom adapter) and add headers and footers before and after your Expandable list.
除了页眉/页脚方法之外,如果您将在 ExpandableList 之前定义所有视图并为其提供相对位置(layout_above/layout_below),您将获得所需的视图。
Apart from header/footer approach if you will define all the view before expandableList and give it relative position (layout_above/layout_below) , u will get the desired view .