ScrollView 仅在其子层次结构中显示单个视图
ScrollView is only showing single view inside its sub-hierarchy
我应该添加一个 ScrollView
,使用户能够在按钮后向下滚动。但是,它没有显示它应该显示的内容。
无论我在 Button
之后添加什么,都不会出现在 device/emulator 上。我应该在 Button
下添加 ImageView
,但在 Button
.
之后似乎没有显示任何内容
以下是我的XML:
<?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:fillViewport="true">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Description:"
android:id="@+id/textView14"
android:paddingTop="20dp"
android:layout_below="@+id/editText"
android:layout_alignLeft="@+id/editText"
android:layout_alignStart="@+id/editText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Restaurant Location:"
android:id="@+id/textView15"
android:paddingTop="20dp"
android:layout_below="@+id/editText2"
android:layout_alignLeft="@+id/editText2"
android:layout_alignStart="@+id/editText2" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button2"
android:layout_below="@+id/imageView3"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</ScrollView>
问题是您没有正确对齐视图。例如,没有 editText2
、editText
和 imageView3
,您将视图对齐到它们的左侧或下方。
将 RelativeLayout
替换为 LinearLayout
或使用此 XML(我已将那些未知 ID 替换为正确的 ID):
<?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:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Description:"
android:paddingTop="20dp" />
<TextView
android:id="@+id/textView15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Restaurant Location:"
android:paddingTop="20dp"
android:layout_below="@+id/textView14" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:layout_below="@id/textView15"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</ScrollView>
我应该添加一个 ScrollView
,使用户能够在按钮后向下滚动。但是,它没有显示它应该显示的内容。
无论我在 Button
之后添加什么,都不会出现在 device/emulator 上。我应该在 Button
下添加 ImageView
,但在 Button
.
以下是我的XML:
<?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:fillViewport="true">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Description:"
android:id="@+id/textView14"
android:paddingTop="20dp"
android:layout_below="@+id/editText"
android:layout_alignLeft="@+id/editText"
android:layout_alignStart="@+id/editText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Restaurant Location:"
android:id="@+id/textView15"
android:paddingTop="20dp"
android:layout_below="@+id/editText2"
android:layout_alignLeft="@+id/editText2"
android:layout_alignStart="@+id/editText2" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button2"
android:layout_below="@+id/imageView3"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</ScrollView>
问题是您没有正确对齐视图。例如,没有 editText2
、editText
和 imageView3
,您将视图对齐到它们的左侧或下方。
将 RelativeLayout
替换为 LinearLayout
或使用此 XML(我已将那些未知 ID 替换为正确的 ID):
<?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:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Description:"
android:paddingTop="20dp" />
<TextView
android:id="@+id/textView15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Restaurant Location:"
android:paddingTop="20dp"
android:layout_below="@+id/textView14" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:layout_below="@id/textView15"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</ScrollView>