【问题标题】:Android Layout won't scroll vertically in landscape orientationAndroid 布局不会在横向垂直滚动
【发布时间】:2011-11-19 20:58:15
【问题描述】:

嗨 Stack Overflow 社区,

我希望您能帮助解决我遇到的 Android 布局问题。当我将其设置为横向时,我似乎无法让我的活动垂直滚动。

我有一个 scrollview 父级和一个 relativelayout 子级。在 relativelayout 中,我有各种元素。纵向看起来很棒,但在横向中,我缩小的图像视图以适合屏幕中的所有内容,而不是具有我想要的垂直滚动。

非常感谢任何帮助并继续编写代码!

-AmarettoSlim

<?xml version="1.0" encoding="utf-8"?>

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ScrollView"
    android:layout_height="fill_parent" android:layout_width="fill_parent" android:fillViewport="true" android:scrollbars="vertical">

    <RelativeLayout android:id="@+id/MainScreen" android:background="@color/appbackground" android:layout_width="fill_parent" android:layout_height="fill_parent" android:isScrollContainer="true" android:scrollbars="vertical" android:scrollbarStyle="insideOverlay">
        <Spinner android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignLeft="@+id/cspinner" android:layout_marginTop="48dp" android:id="@+id/pspinner" android:layout_above="@+id/buttonGo"></Spinner>
        <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@+id/cspinner" android:layout_toLeftOf="@+id/cspinner" android:layout_marginRight="14dp" android:layout_marginTop="14dp" android:id="@+id/labelC" android:text="@string/lblC"></TextView>
        <ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/logo" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="14dp" android:id="@+id/bannerLogo"></ImageView>
        <TextView android:id="@+id/labelPrice" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/lblP" android:layout_alignTop="@+id/pspinner" android:layout_alignRight="@+id/labelC" android:layout_marginTop="16dp"></TextView>
        <Spinner android:layout_height="wrap_content" android:id="@+id/cspinner" android:layout_width="wrap_content" android:layout_above="@+id/labelP" android:layout_centerHorizontal="true"></Spinner>
        <ImageView android:layout_height="wrap_content" android:id="@+id/imgHat" android:layout_width="wrap_content" android:src="@drawable/bowlericon" android:layout_centerHorizontal="true" android:layout_below="@+id/bannerLogo" android:layout_above="@+id/cspinner"></ImageView>
        <Button android:id="@+id/buttonGo" android:layout_width="fill_parent" android:text="@string/btnRun" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true"></Button>
    </RelativeLayout>

</ScrollView>

【问题讨论】:

    标签: android android-layout scroll scrollview android-relativelayout


    【解决方案1】:

    尝试为横向模式制作单独的布局并将其放入

    res/layout-land/
    

    【讨论】:

      【解决方案2】:

      嗯...您提供了一个重要线索:“在 LandScape 中,一切都缩小以适应”。如果一切都合适,没有卷轴是正常的!

      所以我建议将您的 RelativeLayout 高度更改为“包装内容”而不是“填充父项”。这样,如果您的 relativelayout 中的内容超过了滚动视图的高度,您将能够滚动。

      顺便说一句-此外,填充父级现在已过时。您应该改用“匹配父级”!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多