在Android项目布局中添加滚动查看
我想让布局向下滚动。我已经看到一些这样的帖子,我试图做他们解释,但它不适合我。这就是我现在所拥有的,现在我的项目甚至不会开始,可能会导致它错位。在Android项目布局中添加滚动查看
这是我的代码看起来像:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.rodekruis.Bezoek" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginBottom="20dp"
android:src="@drawable/rkz_logo" />
<ScrollView
android:id="@+id/scrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/textView1"
android:layout_width="244dp"
android:layout_height="276dp"
android:layout_gravity="center"
android:text="@string/title_activity_contact"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/black" />
<TextView
android:id="@+id/textView2"
android:layout_width="244dp"
android:layout_height="42dp"
android:layout_gravity="center"
android:layout_weight="0.39"
android:text="Klik hier voor de uitgebreide contactgegevens."
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/black" />
</ScrollView>
</LinearLayout>
ScrollView
只能有一个孩子,所以你应该添加一个Layout Manager
是包装所有布局ScrollView
。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.rodekruis.Bezoek" >
...
<ScrollView
android:id="@+id/scrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="@+id/textView1"
.../>
<TextView
android:id="@+id/textView2"
.../>
</LinearLayout>
</ScrollView>
...
整个代码给我的错误:XML文档必须以相同的实体开始和结束 –
@SneakyAndStuff是否关闭了'LinearLayout'标签。确保你正确地打开和关闭xml标签 –
这样做,能够启动应用程序,仍然无法向下滚动。 –
滚动型有只有一个孩子,并有两个孩子的layuot,使用此spinets
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginBottom="20dp" />
<ScrollView
android:id="@+id/scrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textView1"
android:layout_width="244dp"
android:layout_height="276dp"
android:layout_gravity="center"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/black" />
<TextView
android:id="@+id/textView2"
android:layout_width="244dp"
android:layout_height="42dp"
android:layout_gravity="center"
android:layout_weight="0.39"
android:text="Klik hier voor de uitgebreide contactgegevens."
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/black" />
</LinearLayout>
</ScrollView>
这整个代码给我的错误是:XML文档必须以相同实体开始和结束 –
最后在显示中添加 LinearLayout> – Karthik
我们没有显示LinearLayout的结束标记,您应该添加 LinearLayout>下面的 –
滚动型只有一个孩子,它可以是一个视图组 –