【发布时间】:2016-06-09 10:05:05
【问题描述】:
我正在尝试在我的表单中添加ScrollView。但是每当我添加ScrollView 时,它都会显示“ScrollView 只能容纳一个直接的孩子”。这是什么意思?如何在我的表单中实现ScrollView?这是我的代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/showImage"
android:layout_width="400dp"
android:layout_height="100dp"
android:adjustViewBounds="true"
android:scaleType="fitCenter" />
<!--android:src="@drawable/placeholder"-->
<Button
android:id="@+id/btnSaveImage"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_gravity="center_horizontal"
android:background="#f66565"
android:text="Select Image" />
<EditText
android:id="@+id/editFirstName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Blog Title">
<requestFocus />
</EditText>
<EditText
android:id="@+id/editLastName"
android:layout_width="match_parent"
android:layout_height="150dp"
android:ems="10"
android:hint="Enter Blog Description" />
<EditText
android:id="@+id/editWeb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:ems="10"
android:hint="Enter Web Link">
<requestFocus />
</EditText>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp">
<Button
android:id="@+id/btnNewUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:background="#f66565"
android:text="New Blog" />
<Button
android:id="@+id/btnSaveRecord"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:background="#f66565"
android:text="Save Blog" />
<Button
android:id="@+id/btnfullinfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:background="#f66565"
android:text="Show All" />
</LinearLayout>
</ScrollView>
</LinearLayout>
【问题讨论】:
-
ScrollView中必须有唯一的孩子意味着<ScrollView>--<LinearLayout>--All Other layouts--</LinearLayout></ScrollView> -
ScrollView里面只能有一个元素。将其他元素包含在线性布局中。 -
你们没有谷歌??
-
谢谢阿布舍克·帕特尔 :)
-
@SamiurRahman 总是厕所
标签: android xml scrollview