【问题标题】:Why HorizontalScrollView not scroll in HTCDesire 2.2 but only on simulator?为什么 Horizo​​ntalScrollView 不能在 HTCDesire 2.2 中滚动,而只能在模拟器上滚动?
【发布时间】:2013-04-07 01:17:18
【问题描述】:

我在视图中使用HorizentalScrollView。我在运行时添加TextView。我用horView.smoothScrollTo(x,y);它适用于模拟器。但它不会在 HTCDesire 2.2 处滚动?任何想法?这是我的代码。

horView.smoothScrollTo(num, 0);


<HorizontalScrollView
    android:id="@+id/cate_head"
    android:scrollbars="none"
    android:foregroundGravity="fill_horizontal"
    android:layout_width="fill_parent"
    android:paddingTop="6dip"
    android:background="@drawable/slider_background"
    android:focusable="true"
    android:layout_height="wrap_content">
    <LinearLayout
        android:id="@+id/cate_head_list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center_horizontal"
        android:orientation="horizontal"
        android:layout_marginLeft="10dip"
        android:layout_marginRight="10dip">
    </LinearLayout>
</HorizontalScrollView>

【问题讨论】:

    标签: android android-widget android-layout


    【解决方案1】:

    最后我找到了解决方案。我在创建结束时调用了 smoothScrollTo(x,y)。(我还能把它放在哪里?)问题是在初始化时没有找到大小或长度(但它不应该是,因为我有将所有数据放入其中)。 所以调用 postDealy() 延迟 50 秒。这个对我有用。就是这样。我把它放在 onCreate(); 的末尾。 可能其他人有面糊解决方案...

    new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                horView.smoothScrollTo((scrollAmount), 0);
            }
        }, 50);
    

    【讨论】:

      【解决方案2】:

      你可以使用View.post来避免依赖时间。

      horView.post(new Runnable() {
          public void run() {
              horView.smoothScrollTo((scrollAmount), 0);          
          }
      });
      

      这会在视图附加到屏幕后立即执行。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多