【发布时间】:2017-07-21 11:13:11
【问题描述】:
我正在开发一个带有基本 API11 的 android 应用程序。我想在带有所有其他组件的滚动视图中添加一个列表视图,但我知道这是不对的。因此,我将列表视图设置为静态,就像添加新单元格时扩展一样,但是当我添加滚动视图时,列表视图变为可滚动的。请在下面找到xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/parentLayout">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/parentLayout">
<TextView
android:id="@+id/groupNameTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Group Name"
android:gravity="center"
android:textSize="30sp"
android:layout_marginTop="10dp"/>
<EditText
android:id="@+id/grpName"
android:layout_below="@id/groupNameTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter group name"
android:textAlignment="center"
android:gravity="center"/>
<TextView
android:id="@+id/grpDescriptionTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Group Description"
android:gravity="center"
android:textSize="30sp"
android:layout_marginTop="14dp"
android:layout_below="@+id/grpName"
android:layout_alignParentLeft="true" />
<EditText
android:id="@+id/grpDescription"
android:layout_below="@id/grpDescriptionTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter description"
android:gravity="center"/>
<TextView
android:id="@+id/individualEA"
android:layout_below="@id/grpDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Individual's Email addresses"
android:gravity="center"
android:textSize="30sp"
android:layout_marginTop="10dp"/>
<!--<LinearLayout-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_below="@id/individualEA"-->
<!--android:orientation="horizontal">-->
<ImageButton
android:layout_width="match_parent"
android:id="@+id/addEmailAddressButton"
android:layout_height="40dp"
android:layout_below="@id/individualEA"
android:src="@mipmap/add_button"
android:background="@color/whitecolor" />
<!--</LinearLayout>-->
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/addEmailAddressButton"
android:id="@+id/eaListView" />
<LinearLayout
android:id="@+id/twoButtonsLayout"
android:layout_width="match_parent"
android:layout_below="@id/eaListView"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/updateButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/create_account_button_bg"
android:text="Update"
android:layout_below="@id/eaListView"
android:padding="7dp"
android:layout_weight="1"
android:layout_margin="7dp"
android:layout_marginTop="30dp"
android:textColor="@color/whitecolor"
android:textSize="40sp" />
<Button
android:id="@+id/deleteButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/delete_account_button_bg"
android:text="Delete"
android:layout_below="@id/eaListView"
android:layout_margin="7dp"
android:padding="7dp"
android:layout_weight="1"
android:textColor="@color/whitecolor"
android:textSize="40sp" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
下面的屏幕截图是我需要的,但屏幕不可滚动,列表视图静态且可扩展。当我评论滚动视图和相对布局时会发生这种情况。
为了使其可滚动,我添加了滚动视图和相对布局,但滚动视图使列表视图可滚动并减小了列表视图的大小,如下面的屏幕截图所示。
在横向模式下,它通过使屏幕可滚动和静态列表视图以另一种方式工作。
我的问题是如何使屏幕可滚动,列表视图静态并像第一个屏幕截图一样纵向和横向扩展?
P.s:我曾想过使用回收站视图和卡片视图,但基本 API 太旧,因此我无法继续使用。
谢谢
【问题讨论】:
-
为什么不试试 ExpandableHeightListView
-
你试过 NestedScrollView 吗? developer.android.com/reference/android/support/v4/widget/…
标签: android listview android-scrollview