简体   繁体   中英

HorizontalScrollView inside a RelativeLayout: works fine on a 1.6+API, but not on 1.5 API

I am using a HorizontalScrollView inside a RelativeLayout . It works fine on a 1.6+API, but on 1.5 API the HorizontalScrollView does not scroll, what is the problem?

On 1.5 API (3) you can only see the first part of the HorizontalScrollView and there's no scrolling at all, while it seems to work fine on API4 and above.

To answer question, here's some code used:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout    xmlns:android="http://schemas.android.com/apk/res/android"    

xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"    
android:layout_height="fill_parent"
android:orientation="vertical"     >   

<HorizontalScrollView
 android:id="@+id/pscroll"
android:scrollbars="horizontal"
android:orientation="horizontal"
android:layout_width="fill_parent"    
android:layout_height="wrap_content"
android:layout_below="@id/ad"
android:fillViewport="true"
android:scrollbarAlwaysDrawHorizontalTrack="true">      

<LinearLayout android:orientation="horizontal" android:id="@+id/LinearLayout01"       android:scrollbars="horizontal" android:layout_width="fill_parent"    android:layout_height="wrap_content">
                  <ImageButton android:id="@+id/P1"  android:layout_width="wrap_content" android:layout_height="wrap_content" />
           <ImageButton android:id="@+id/P2"  android:layout_width="wrap_content" android:layout_height="wrap_content"/>

Edit: refined, based off of negative feedback (apparently people expect their hand to be held through this)

A scroll view is meant to contain a layout, not the reversal of that. Therefore your layout should be:

<HorizontalScrollView android:id="@+id/pscroll"
    android:scrollbars="horizontal" android:orientation="horizontal"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:layout_below="@id/ad" android:fillViewport="true"
    android:scrollbarAlwaysDrawHorizontalTrack="true">
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

        xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:orientation="vertical">

        <LinearLayout android:orientation="horizontal"
            android:id="@+id/LinearLayout01" android:scrollbars="horizontal"
            android:layout_width="fill_parent" android:layout_height="wrap_content">
            <ImageButton android:id="@+id/P1" android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
            <ImageButton android:id="@+id/P2" android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </LinearLayout>
    </RelativeLayout>
</HorizontalScrollView>

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