[英]Android Scrollview doesn't wrap child
Here's the Layout xml file: 这是布局xml文件:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:scrollbars = "vertical">
<LinearLayout
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="factory.Settings"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/lblShopID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ShopId"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/txtShopID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="text"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/lblShopname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/lblShopID"
android:layout_marginTop="36dp"
android:text="@string/ShopName"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="@+id/spinShopName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/lblShopname"
android:layout_toRightOf="@+id/lblShopname" />
</LinearLayout>
<Button
android:id="@+id/btnSaveChanges"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/spinShopName"
android:layout_marginTop="22dp"
android:onClick="saveData"
android:text="Save Changes" />
<TextView
android:id="@+id/txtChangePassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:text="@string/ChangePassword"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginTop="30px" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30px">
<TextView
android:id="@+id/lblOldPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/OldPassword"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/txtOldPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/lblNewPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/NewPassword"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/txtNewPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/lblRetypePassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/RetypePassword"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/txtRetypePassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
</LinearLayout>
<Button
android:id="@+id/btnChangePassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="changePassword"
android:text="Change Password" />
<ListView
android:id="@+id/lstUsers"
android:layout_width="340dp"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
And Here's the expecting output: 这是预期的输出:
The expected output is : I have some items in lstUsers
and there wouldn't be enough space for displaying all the users, so I would like to add a scrollview to the Layout to let users scroll down. 预期的输出是:我在
lstUsers
有一些项目,并且没有足够的空间来显示所有用户,因此我想向Layout中添加一个scrollview以使用户向下滚动。
But the problem is: the scrollview doesn't wrap any controls at all, the outcome is: 但是问题是:scrollview根本不包装任何控件,结果是:
As you can see, the scrollview is unable to wrap the lstUser 如您所见,scrollview无法包装lstUser
Is there anything wrong with the layout file? 布局文件有什么问题吗?
I don't think you are allowed to put a listview in a scrollview. 我认为您不允许在滚动视图中放置一个列表视图。 Listview implements its own scroller so it doesn't like being in a scrollview.
Listview实现了自己的滚动器,因此它不喜欢处于滚动视图中。 Take a look at this link
看看这个链接
How can I put a ListView into a ScrollView without it collapsing? 如何在不折叠的情况下将ListView放入ScrollView?
Scrollview and Listview do not work well with each other. Scrollview和Listview不能很好地配合使用。
What I would suggest u is to make 'lstUsers' Listview the main content of the layout file. 我建议您使“ lstUsers” Listview成为布局文件的主要内容。
Create a separate layout file with the views that are above the listview. 使用listview上方的视图创建一个单独的布局文件。
Then inflate this layout file and add it as a header view to the listview. 然后,膨胀该布局文件,并将其作为标题视图添加到列表视图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.