Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ScrollView在底部添加了较大的空间_Android_Android Scrollview - Fatal编程技术网

Android ScrollView在底部添加了较大的空间

Android ScrollView在底部添加了较大的空间,android,android-scrollview,Android,Android Scrollview,我的主要活动有许多按钮,在一个大的平板电脑屏幕上,这些按钮相互下方,但在一个小的手机屏幕上却没有。我添加了一个ScrollView,这样,如果屏幕大小需要,用户可以向下滚动到其他按钮: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wr

我的主要活动有许多按钮,在一个大的平板电脑屏幕上,这些按钮相互下方,但在一个小的手机屏幕上却没有。我添加了一个ScrollView,这样,如果屏幕大小需要,用户可以向下滚动到其他按钮:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical"
          android:background="@drawable/bg"
          android:gravity="center_horizontal">

    <TextView
        android:id="@+id/trackSelectorText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"/>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"                
            android:gravity="center_horizontal">

        <Button                    
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="foo" />
        <!-- More buttons -->
        </LinearLayout>
    </ScrollView>
</LinearLayout>

这有点可行,但是我在最后一个按钮下面有一个很大的空白(即ScrollView可能向下滚动太远)。无论是在实际平板电脑上还是在带有电话配置的模拟器上。如果我
center
内线布局(而不是
center\u horizontal
),则空间均匀分布在顶部和底部之间,这两者我都不想要。如何修复此布局

我希望这张图片能让它更清晰,想象一下ScrollView已经完全向下滚动并显示最后的按钮。空白的意思是右图像下面的按钮6:


我已经检查了我的代码..工作完美:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      android:background="@drawable/bg"
      android:gravity="center_horizontal">

<TextView
    android:id="@+id/trackSelectorText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"/>

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"                
        android:gravity="center_horizontal">

    <Button                    
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="foo" />
    <!-- More buttons -->
    </LinearLayout>
  </ScrollView>
</LinearLayout>


可能会帮助你

尝试将此属性添加到ScrollView元素中。 android:fillViewport=“true”

。。。

Ref:

事实上,它与布局没有真正的关系(除非我遗漏了什么)。我试着对背景进行评论,结果突然奏效了。背景图像(
@drawable/bg
)太大,导致了滚动。我把背景转换成了一个9块的图像,这样它就可以自动缩放,瞧,额外的空间消失了。
尽管如此,如果不使用9-patch就可以实现这一点,我仍然很想知道这是否可以在XML文件中实现。

您可以在scrollview中使用此属性,以避免在视图底部添加额外的填充

android:overScrollMode="never"

你能画出你想要的东西吗?完成了,我希望这能使它更容易可视化。试着给出
滚动视图
android:layout\u height=“match\u parent”
。我怀疑这个空间在scrollview中,但实际上它在下面,Lenart,将scrollview环绕在一个垂直的线性布局上,放置
maxWeightSum=3
,并给每个按钮一个
weigth=1
。完成:)LinearLayout应填充\u父对象,滚动布局应定义线性布局的视口大小。android:layout\u height=“match\u parent”应更改为android:layout\u height=“0dp”
android:overScrollMode="never"