【问题标题】:How Do I Make my Screen Scrollable in Android Eclipse如何在 Android Eclipse 中使我的屏幕可滚动
【发布时间】:2013-07-25 17:16:23
【问题描述】:
这是我尝试将其调整为可滚动之前的 XML 代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- all my widgets -->
</RelativeLayout>
如何编辑它以使其可滚动?从小部件列表中拖动ScrollView 只会把一切搞砸。
【问题讨论】:
标签:
android
xml
android-layout
【解决方案1】:
确保将version/encoding 行保留在文件的最顶部。
将RelativeLayout 更改为ScrollView,然后在新的ScrollView 中嵌套RelativeLayout 部分(包含所有小部件)。
确保为RelativeLayout 提供一些尺寸,这些尺寸应与ScrollView 的width 和height 尺寸相同。
包含所有小部件的RelativeLayout 嵌套的原因是ScrollView 元素只能有一个子元素(在这种情况下,RelativeLayout,然后有自己的子元素)。
因此这段代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- all your widgets -->
</RelativeLayout>
变成这段代码:
<?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" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- all your widgets -->
</RelativeLayout>
</ScrollView>