滚动 Android 视图/表单大于屏幕尺寸

发布于 2024-12-01 19:07:18 字数 529 浏览 1 评论 0原文

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

目前我所有的小部件都采用线性布局。

<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> 

I have view/form/activity, when displayed in landscape/horizontal mode, become bigger than screen size. I was wondering what is the way in which user can scroll down the view?

Currently all of my widgets are in the Linear layout as fellows.

<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> 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

佞臣 2024-12-08 19:07:18

如果我正确理解你的问题:你可以在 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>  

If I understand your question correctly: you could have a ScrollView outside your LinearLayout and have a HorizontalScrollView inside your LinearLayout, where you could add your Widgets. This will allow you to scroll both left-right and top-down.

Example Code:

<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>  
扎心 2024-12-08 19:07:18

首先感谢 @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>

First thanks for the @Dimitris Makris in helping me out to find the right direction and writing the code for me. But the correct solution which I have found for myself is this.

<?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>
樱花细雨 2024-12-08 19:07:18

对我的情况有效的是将 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>

What worked for my situation was to put the ScrollView as the outer-most view,
followed by HorizontalScrollView, and then nested everything inside.

*NOTE - ScrollView does not support horizontal scrolling, hence the nested HorizontalScrollView.

<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文