开发者

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

开发者 https://www.devze.com 2023-04-12 05:20 出处:网络
I am using a HorizontalScrollViewinside a RelativeLayout.It works fine on a 1.6+API, but on 1.5 API the HorizontalScrollView does not scroll, what is the problem?

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开发者_JS百科: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>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号