【问题标题】:Horizontal scroll view does not scroll properly水平滚动视图无法正确滚动
【发布时间】:2014-01-13 09:25:41
【问题描述】:

我有一个水平滚动视图,它仅水平移动 100 dp,而它应该更宽,而不是滚动所有内容。我能做什么?

<HorizontalScrollView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:fillViewport="true">

    <LinearLayout
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginTop="10dp" 
      android:orientation="vertical">

        <LinearLayout
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginTop="10dp"
          android:orientation="horizontal" >

           <TextView
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:layout_marginLeft="10dp"
            android:gravity="center_vertical"
            android:text="@string/oggi"
            android:textSize="12dp" />

          <LinearLayout
            android:layout_marginLeft="10dp"
            android:layout_width="455dp"
            android:layout_height="2dp"
            android:background="#000000"
           android:layout_gravity="center"
           android:orientation="horizontal" >

          </LinearLayout>

         <TextView
           android:layout_width="wrap_content"
           android:layout_height="30dp"
           android:layout_marginLeft="10dp"
           android:gravity="center_vertical"
           android:text="@string/domani"
           android:textSize="12dp" />

       <LinearLayout
           android:layout_marginLeft="10dp"
           android:layout_width="455dp"
           android:layout_height="2dp"
           android:background="#000000"
           android:layout_gravity="center"
           android:orientation="horizontal" >
      </LinearLayout>

      <TextView
          android:layout_width="wrap_content"
          android:layout_height="30dp"
          android:layout_marginLeft="10dp"
          android:gravity="center_vertical"
          android:text="@string/prossime"
         android:textSize="12dp" />

     <LinearLayout
        android:layout_marginLeft="10dp"
        android:layout_width="400dp"
        android:layout_height="2dp"
        android:background="#000000"
        android:layout_gravity="center"
        android:orientation="horizontal" >
     </LinearLayout>   

  </LinearLayout>


  <!-- Slideshow horz gridview single row -->
 <com.jess.ui.TwoWayGridView
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/dashboard_grid_giorni"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_width="match_parent"
        android:layout_height="180dp"
        android:background="#E8E8E8"
    app:cacheColorHint="#E8E8E8"
    app:verticalSpacing="0dp"
    app:horizontalSpacing="10dp"
    app:scrollDirectionPortrait="horizontal"
    app:scrollDirectionLandscape="horizontal"
    />

 </LinearLayout>

 </HorizontalScrollView>

【问题讨论】:

  • 请尝试使用
  • Horizo​​ntalScrollView 表示您的内容水平滚动,因此将您的 Horizo​​ntalScrollView 宽度从 wrap_content 更改为 match_parent。
  • 匹配父级无效,我得到同样的错误

标签: android horizontal-scrolling


【解决方案1】:

我不是 100% 确定,但您是否尝试让您的滚动视图填充父级?如果您的滚动视图和布局具有相同的大小,则使用滚动视图毫无意义。 ScrollView 需要有一个大小,这样如果布局超出了您的滚动视图的大小,您就可以滚动。

【讨论】:

  • 您是否检查过您的自定义网格视图是否已预先实现滚动视图?因为这意味着您有嵌套的滚动视图并且它们不正常。!由于您的网格视图是匹配父级,我猜您需要水平滚动因为您的文本视图长度?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-01
相关资源
最近更新 更多