【问题标题】:Scrolling Android View/Form bigger than screen size滚动大于屏幕尺寸的Android视图/表单
【发布时间】:2011-08-28 10:22:05
【问题描述】:

我有视图/表单/活动,当以横向/横向模式显示时,会变得比屏幕尺寸大。我想知道用户向下滚动视图的方式是什么?

目前我所有的小部件都在线性布局中。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:isScrollContainer="true">

<Widget1></Widget1>
<Widget2></Widget2>
<Widget3></Widget3>
<Widget4></Widget4>
<Widget5></Widget5>
</LinearLayout> 

【问题讨论】:

    标签: android view android-layout android-activity scroll


    【解决方案1】:

    如果我正确理解您的问题:您可以在 LinearLayout 之外有一个 ScrollView,在 LinearLayout 中有一个 Horizo​​ntalScrollView,您可以在其中添加小部件。这将允许您左右滚动和自上而下滚动。

    示例代码:

    <ScrollView android:id="@+id/scrollView1"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <LinearLayout android:id="@+id/linearLayout1"
        android:layout_width="match_parent" android:layout_height="match_parent"
        android:orientation="vertical">
        <HorizontalScrollView android:id="@+id/horizontalScrollView1"
            android:layout_width="wrap_content" android:layout_height="wrap_content">
            <LinearLayout android:id="@+id/linearLayout2"
                android:layout_width="match_parent" android:layout_height="match_parent"
                android:orientation="horizontal">
                <Widget1/>
                <Widget2/>
            </LinearLayout>
        </HorizontalScrollView>
    </LinearLayout>
    </ScrollView>  
    

    【讨论】:

    • 并根据您的要求将 android:orientation 属性设置为 HORIZONTAL/VERTICAL
    • @Dimitris Markis - 你能给出示例代码吗?我完全糊涂了。
    【解决方案2】:

    首先感谢@Dimitris Makris 帮助我找到正确的方向并为我编写代码。但我为自己找到的正确解决方案是这样的。

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView android:id="@+id/scrollView1"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">
    
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    
    <Widget1/>
    <Widget2/>
    
    </LinearLayout>
    </ScrollView>
    

    【讨论】:

      【解决方案3】:

      对我的情况有用的是把 ScrollView 作为最外层的视图, 其次是Horizo​​ntalScrollView,然后把所有东西都嵌套在里面。

      *注意 - ScrollView 不支持水平滚动,因此嵌套了 Horizo​​ntalScrollView。

      <ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/scroller"    
        android:layout_width="fill_parent"    
        android:layout_height="fill_parent"
        android:fillViewport="true">
        <HorizontalScrollView
          android:id="@+id/horizontalScrollView1"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent">
          <LinearLayout
            ...
          </LinearLayout>
        </HorizontalScrollView>
      </ScrollView>
      

      【讨论】:

        猜你喜欢
        • 2012-05-31
        • 1970-01-01
        • 2023-03-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-04-21
        • 1970-01-01
        相关资源
        最近更新 更多