android会使滚动视图的底部消失
我正在制作一个带有scrollview的android应用程序,在scrollview中有一个relativelayout,它们都有背景,工作正常,但当我尝试使用marginTop和Bottom在scrollview和relativelayout之间留出空间时,scrollview的底部消失了android会使滚动视图的底部消失,android,layout,scrollview,android-relativelayout,Android,Layout,Scrollview,Android Relativelayout,我正在制作一个带有scrollview的android应用程序,在scrollview中有一个relativelayout,它们都有背景,工作正常,但当我尝试使用marginTop和Bottom在scrollview和relativelayout之间留出空间时,scrollview的底部消失了 <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.c
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="400dp"
android:layout_height="fill_parent"
android:background="@drawable/bg"
>
<RelativeLayout
android:layout_width="330dp"
android:layout_height="730dp"
android:layout_marginLeft="26dp"
android:layout_marginRight="26dp"
android:layout_marginTop="26dp"
android:layout_marginBottom="26dp"
android:background="@drawable/bg2"
>
<Button
android:id="@+id/button1"
android:layout_width="100dp"
android:layout_height="30dp" />
<Button
android:id="@+id/button2"
android:layout_width="100dp"
android:layout_height="30dp" />
<Button
android:id="@+id/button3"
android:layout_width="100dp"
android:layout_height="30dp" />
</RelativeLayout>
</ScrollView>
当我运行应用程序时,我希望:
但我明白了,我看不到底部:
在滚动视图中使用此选项:
android:fillViewport="true"
相对而言:
android:adjustViewBounds="true"
请将此行添加到视图XML文件中的
标记中
android:padding="15dp"
它将解决您的问题。
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#15375e"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:background="#000000"
>
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_margin="10dp"
android:text="1" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_below="@+id/button1"
android:layout_height="40dp"
android:layout_margin="10dp"
android:text="2" />
<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_below="@+id/button2"
android:layout_height="40dp"
android:layout_margin="10dp"
android:text="3"/>
<Button
android:id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_margin="10dp"
android:layout_below="@+id/button3"
android:text="4" />
<Button
android:id="@+id/button5"
android:layout_width="match_parent"
android:layout_below="@+id/button4"
android:layout_height="40dp"
android:layout_margin="10dp"
android:text="5" />
<Button
android:id="@+id/button6"
android:layout_width="match_parent"
android:layout_below="@+id/button5"
android:layout_height="40dp"
android:layout_margin="10dp"
android:text="6"/>
</RelativeLayout>
</ScrollView>
如果您使用上述代码,您将得到如下输出。希望这对您有所帮助。我刚刚偶然发现了这个问题并找到了解决方案 如果在scrollview中设置布局的底部边距,它的行为似乎与预期不符。作为解决方案,您可以设置该元素的填充,而不是边距。如果你想要一个占据整个屏幕的背景,你可以在scrollview上设置它 例如:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:orientation="vertical">
<!--Your elements go here-->
</LinearLayout>
</ScrollView>
希望这对别人有帮助 将android:layout_marginBottom=“26dp”从
RelativeLayout
中删除并检查它。。仅使用marginTop
你能告诉我们你得到了什么和你想要什么吗?我在问题中添加了我得到的和我想要的,你为什么要使用硬编码的
值?如果您这样做,那么您的布局不适合所有屏幕。在XML中只有3个按钮,运行时如何得到7个按钮?我有很多按钮,但我放了3个按钮。不幸的是,它不起作用。我还尝试填充底部和顶部。为什么不能添加超过6个按钮?。您可以添加任意数量的按钮。