在Android中使用ScrollView
我在屏幕上有一个很长的文本,所以滚动是唯一的选择。但是,当我进入ScrollView时,一个错误显示为 未设置所需的布局高度属性: 1设置为包装内容 2设置为与父项匹配 未设置所需的布局宽度属性: 1设置为包装内容 2设置为与父项匹配 未设置所需的布局高度属性: 1设置为包装内容 2设置为与父项匹配 必须提供布局高度属性 这是我的.xml文件在Android中使用ScrollView,android,android-layout,uiscrollview,Android,Android Layout,Uiscrollview,我在屏幕上有一个很长的文本,所以滚动是唯一的选择。但是,当我进入ScrollView时,一个错误显示为 未设置所需的布局高度属性: 1设置为包装内容 2设置为与父项匹配 未设置所需的布局宽度属性: 1设置为包装内容 2设置为与父项匹配 未设置所需的布局高度属性: 1设置为包装内容 2设置为与父项匹配 必须提供布局高度属性 这是我的.xml文件 <ScrollView xmlns:tools="http://schemas.android.com/tools" android
<ScrollView
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
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="com.example.projextxy.CityInfo" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text=" all the text goes in here "
android:textAppearance="?android:attr/textAppearanceMedium" />
</ScrollView>
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_width="match_parent" >
</ScrollView>
我猜您使用布局编辑器拖放了scrollview,结果看起来很奇怪,因为您发布的是一个格式完全错误的XML文件 为了简化,只需删除所有属性,问题就显而易见了:
<ScrollView <-- start a ScrollView
>
<TextView <-- start and end a TextView
/>
</ScrollView> <-- end a ScrollView
</RelativeLayout> <-- end a RelativeLayout
<ScrollView <-- start a ScrollView
>
</ScrollView> <-- end a ScrollView
正如你所看到的,这完全是不正常的。只需将其更改为:
<ScrollView
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
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="com.example.projextxy.CityInfo" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text=" all the text goes in here "
android:textAppearance="?android:attr/textAppearanceMedium" />
</ScrollView>
其余部分不需要您包含的代码似乎不完整。请发布布局XML文件的完整内容,并指出错误发生在哪一行。@cygery这是完整的XML文件。该错误发生在TextView布局\u alignParentLedt和布局\u alignParentTop中。它在滚动视图中显示无效的布局参数,您有一个结束标记,但没有相应的开始标记。