【问题标题】:Gap between last button an LinearLayout最后一个按钮与 LinearLayout 之间的间隙
【发布时间】:2014-02-13 16:09:53
【问题描述】:

我的问题是,在我的布局中,视图的最后一个元素(它是一个按钮)和视图的“底部”之间存在很大差距。 我在ScrollView 中使用LinearLayout。我的错在哪里?我尝试将所有填充设置为 0dp,但仍然存在同样的问题。

<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"
android:padding="0dp"
tools:context=".MainMenu">

<LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
           android:orientation="vertical"
        android:background="@drawable/bg_ohne"

    >

       <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="126dp"
        android:paddingTop="5dp"
                android:layout_gravity="center"
        android:contentDescription="seas"      
        android:src="@drawable/logo" />

     <Button
        android:id="@+id/btLineup"
        android:layout_marginTop="60dp"
        android:layout_gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/lineup"
        />

    <Button
        android:id="@+id/btZumSpiel"
        android:paddingTop="10dp"
        android:layout_gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/wegweiserzumspiel"/>


            <Button
                android:id="@+id/btHighscore"
                android:layout_gravity="center"
                android:layout_width="wrap_content"
                android:paddingTop="10dp"
                android:paddingBottom="0dp"
                android:layout_marginBottom="0dp"
                android:layout_height="wrap_content"
                android:background="@drawable/highscore" />
</LinearLayout>

</ScrollView>

【问题讨论】:

  • 您希望您的视图锚定到屏幕底部吗?看起来您的视图不会比能够滚动的屏幕大
  • 您希望名称为“btHighscore”的按钮靠近底部吗?
  • 我在屏幕顶部看到我的按钮应该在的位置。在我的最后一个按钮之后,有一个没有元素的大间隙。
  • 是的,应该是最后一个

标签: android layout view scrollview android-linearlayout


【解决方案1】:

用最后一个按钮替换这段代码并注意这一行 android:layout_marginTop="40dp" 现在您可以增加或减少该值。

<Button
                android:id="@+id/btHighscore"
                android:layout_gravity="center"
                android:layout_width="wrap_content"
                android:paddingTop="10dp"
                android:paddingBottom="0dp"

                android:layout_marginTop="40dp"

                android:layout_marginBottom="0dp"
                android:layout_height="wrap_content"
                android:background="@drawable/btnblue" />

【讨论】:

  • 使用此代码,按钮向下移动了 40dp,但按钮与底部之间仍有很大的差距..
  • 然后将背景应用到不是线性滚动视图的父视图上
【解决方案2】:

我找到了解决办法:

设置

android:background 

进入ScrollView标签,它就可以工作了!

【讨论】:

    猜你喜欢
    • 2012-10-31
    • 2011-09-05
    • 2015-10-15
    • 1970-01-01
    • 1970-01-01
    • 2012-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多