Java 实现ScrollView会导致致命异常
我有一个RelativeLayout,我正在尝试添加向下滚动的功能-当设备处于水平位置时。(当前-水平翻转按钮时,按钮消失-这是不需要的。) 当前XML状态:Java 实现ScrollView会导致致命异常,java,android,xml,scrollview,android-scrollview,Java,Android,Xml,Scrollview,Android Scrollview,我有一个RelativeLayout,我正在尝试添加向下滚动的功能-当设备处于水平位置时。(当前-水平翻转按钮时,按钮消失-这是不需要的。) 当前XML状态: ScrollView只能有一个子元素。您有3个按钮、ImageView和TextView。尝试使用滚动视图包装您的相对视图: <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/r
ScrollView
只能有一个子元素。您有3个按钮、ImageView和TextView。尝试使用滚动视图
包装您的相对视图
:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:orientation="vertical" >
<Button
android:id="@+id/go_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text"
android:layout_centerHorizontal="true"
android:layout_marginTop="85dp"
android:background="@drawable/apn_app_go_button" />
<ImageView
android:id="@+id/emblem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:gravity="center"
android:scaleType="fitStart"
android:src="@drawable/apn_app_logo" />
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/emblem"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="@string/start_text"
android:textColor="#000000"
android:textSize="14sp" />
</RelativeLayout>
</ScrollView>
滚动视图只能有一个子元素。您有3个按钮、ImageView和TextView。尝试使用
滚动视图
包装您的相对视图
:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:orientation="vertical" >
<Button
android:id="@+id/go_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text"
android:layout_centerHorizontal="true"
android:layout_marginTop="85dp"
android:background="@drawable/apn_app_go_button" />
<ImageView
android:id="@+id/emblem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:gravity="center"
android:scaleType="fitStart"
android:src="@drawable/apn_app_logo" />
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/emblem"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="@string/start_text"
android:textColor="#000000"
android:textSize="14sp" />
</RelativeLayout>
</ScrollView>
将代码替换为:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:orientation="vertical" >
<Button
android:id="@+id/go_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text"
android:layout_centerHorizontal="true"
android:layout_marginTop="85dp"
android:background="@drawable/apn_app_go_button" />
<ImageView
android:id="@+id/emblem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:gravity="center"
android:scaleType="fitStart"
android:src="@drawable/apn_app_logo" />
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/emblem"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="@string/start_text"
android:textColor="#000000"
android:textSize="14sp" />
</RelativeLayout>
</ScrollView>
将代码替换为:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:orientation="vertical" >
<Button
android:id="@+id/go_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text"
android:layout_centerHorizontal="true"
android:layout_marginTop="85dp"
android:background="@drawable/apn_app_go_button" />
<ImageView
android:id="@+id/emblem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:gravity="center"
android:scaleType="fitStart"
android:src="@drawable/apn_app_logo" />
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/emblem"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="@string/start_text"
android:textColor="#000000"
android:textSize="14sp" />
</RelativeLayout>
</ScrollView>
ScrollView不能在其中添加两个以上的视图。。。。因此,在ScrollView中,最好使用一个LinearLayout或RelativeLayout,然后在其中添加其他布局。。最后在其中添加子视图…ScrollView不能在其中添加两个以上的视图。。。。因此,在ScrollView中,最好使用一个LinearLayout或RelativeLayout,然后在其中添加其他布局。。最后在其中添加子视图…您需要删除RelativeLayout的xmlns
标记。每个xml文档只需要一个名称空间(ns)。我更新了代码。您需要删除RelativeLayout的xmlns
标记。每个xml文档只需要一个名称空间(ns)。我更新了我的代码。
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:orientation="vertical" >
<Button
android:id="@+id/go_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text"
android:layout_centerHorizontal="true"
android:layout_marginTop="85dp"
android:background="@drawable/apn_app_go_button" />
<ImageView
android:id="@+id/emblem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:gravity="center"
android:scaleType="fitStart"
android:src="@drawable/apn_app_logo" />
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/emblem"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="@string/start_text"
android:textColor="#000000"
android:textSize="14sp" />
</RelativeLayout>
</ScrollView>