【问题标题】:ScrollView with GridLayout doesn't start at top带有 GridLayout 的 ScrollView 不会从顶部开始
【发布时间】:2020-09-03 09:57:22
【问题描述】:

即使在设计视图中,它也是从中间某处开始的,我无法向上滚动,只能向下滚动。类似地,当我运行应用程序时,它会在中间某处显示内容,我只能向下滚动,似乎最高点是我开始的地方。不知道是margin问题还是其他问题

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<GridLayout
    android:id="@+id/GridLayout1"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:columnCount="2"
    android:rowCount="16"
    android:orientation="horizontal"
    tools:context=".MainActivity" >
    
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:id="@+id/myFrame">
        <ImageView
            android:id="@+id/my_img1"
            android:layout_width="190dp"
            android:layout_height="105dp"
            android:layout_margin="4dp"
            android:src="@drawable/ic_img"/>
        <TextView
            android:id="@+id/descTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="4dp"
            android:layout_marginBottom="34dp"
            android:background="@android:color/transparent"
            android:text="@string/text_1"
            android:textColor="@android:color/black"
            android:textSize="16sp"
            android:textStyle="bold"/>
    </FrameLayout>
    .
    .
    .

框架布局重复 32 次。

【问题讨论】:

  • 垂直滚动视图中列数为 2 的水平网格布局?? FrameLayout 也没有方向,仅供参考
  • 横向网格布局有问题吗?
  • 如果你想水平滚动使用水平滚动视图,如果你有一个滚动视图,滚动视图的第一个孩子需要是一个像垂直线性布局一样垂直扩展的布局,
  • 我将网格布局(ScrollView 的子项)的方向从水平更改为垂直,但它只更改了项目的排列方式,它仍然不是从顶部开始而是从中间开始.当孩子水平时我也可以垂直滚动。

标签: android android-layout android-scrollview android-gridview


【解决方案1】:

通过从 GridLayout 中删除 android:layout_gravity="center" 解决。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-28
    • 1970-01-01
    • 1970-01-01
    • 2015-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多