【问题标题】:android horizontal vertical scroll layout with centerandroid水平垂直滚动布局与中心
【发布时间】:2012-09-17 22:02:34
【问题描述】:

我需要在 xml 中创建 like this 的内容,但无法使用子 Horizo​​ntalScrollView 在 scrollView 中居中内部对象。

这里是代码示例:

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="5"
    android:fillViewport="true" >

    <HorizontalScrollView
        android:id="@+id/horizontalScrollView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >

            <TableLayout
                android:id="@+id/matrix_table"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true" >

                <!-- auto generated rows -->

            </TableLayout>

        </RelativeLayout>

    </HorizontalScrollView>

</ScrollView>

这里是unexpected result

谢谢!

【问题讨论】:

    标签: android xml centering horizontalscrollview


    【解决方案1】:

    将子视图设置为fill_parent 在 ScrollViews 中效果不佳。相反,您应该将子视图尺寸设置为 wrap_content 并使用 layout_gravity

    <HorizontalScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    
        <TableLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center" >
        ...
    
    </HorizontalScrollView>
    

    【讨论】:

      猜你喜欢
      • 2019-12-11
      • 2013-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-26
      相关资源
      最近更新 更多