简体   繁体   中英

Scrolling Android View/Form bigger than screen size

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> 

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>  

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>

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM