【问题标题】:HorizontalScrollView inside a RelativeLayout: works fine on a 1.6+API, but not on 1.5 APIRelativeLayout 内的 Horizo​​ntalScrollView:在 1.6+API 上工作正常,但在 1.5 API 上不行
【发布时间】:2011-10-10 18:04:16
【问题描述】:

我在RelativeLayout 中使用HorizontalScrollView。它在 1.6+API 上运行良好,但在 1.5 API 上 HorizontalScrollView 不滚动,这是什么问题?

在 1.5 API (3) 上,您只能看到 HorizontalScrollView 的第一部分,根本没有滚动,而在 API4 及更高版本上似乎可以正常工作。

为了回答问题,这里使用了一些代码:

<?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"/>

【问题讨论】:

  • 你能发布你用来创建布局的标记吗?
  • 顺便说一句,为 1.6 之前的 android 开发很像在 Windows 98 上开发现代应用程序。当然,有一些商业案例,但是......在某些时候你应该放手:)

标签: java android scrollview horizontalscrollview


【解决方案1】:

编辑:完善,基于负面反馈(显然人们希望他们的手能通过这个)

滚动视图意味着包含一个布局,而不是它的反转。因此你的布局应该是:

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

【讨论】:

  • 请仔细阅读该问题特定于 Horizo​​ntalScroll 视图在 1.5 中未按预期工作,但在 1.6 API 级别 4 中运行良好
  • 没有理由标记我的答案。他可以用“ScrollView”代替“Horizo​​ntalScrollView”。我确实读过这个问题,答案是他正在反转他放置布局和滚动视图的位置。滚动视图应该包含一个布局,这就是我在这里提到的。我不会给出一个不需要思考就能理解的答案,而你显然没有理解我的答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-13
  • 1970-01-01
  • 2015-03-17
相关资源
最近更新 更多