【问题标题】: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 只会把一切搞砸。

【问题讨论】:

  • 我不反对..
  • @753 在我看来你没有接受任何答案

标签: android xml android-layout


【解决方案1】:

确保将version/encoding 行保留在文件的最顶部。

RelativeLayout 更改为ScrollView,然后在新的ScrollView 中嵌套RelativeLayout 部分(包含所有小部件)。

确保为RelativeLayout 提供一些尺寸,这些尺寸应与ScrollViewwidthheight 尺寸相同。

包含所有小部件的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>

【讨论】:

    猜你喜欢
    • 2021-11-29
    • 2019-12-01
    • 2021-02-19
    • 2016-07-06
    • 1970-01-01
    • 1970-01-01
    • 2019-02-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多