我目前正在使用ScrollView中包含RelativeLayout的布局。
我希望RelativeLayout包含在距离ScrollView底部5dp的位置,因此它不会与我背后的背景重叠,为了实现这一点,我使用了这个XML:
<ScrollView
android:id="@+id/scrollView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/backgroundView1"
android:fadingEdge="none"
android:scrollbars="none"
android:paddingTop="5dp"
android:paddingBottom="5dp">
<RelativeLayout
android:id="@+id/innerLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</RelativeLayout>
</ScrollView>
这很好用,但我不再需要在顶部填充。删除paddingTop行时,paddingBottom不再起作用。即使我将paddingBottom设置为100dp,它也不会对我的布局产生影响。
我尝试了paddingTop =“0dp”并且也没有解决问题,看起来paddingBottom只有在paddingTop高于0时才能工作。
任何人都有任何想法,为什么paddingBottom没有paddingTop不起作用?
使用这种布局滚动视图并根据您的需要进行更改。不要在scrollview中使用相对布局。在这里你可以在图像中设置任何类型的高度,你仍然会看到底部的填充没有任何paddingtop
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/backgroundView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#cccccc"
android:paddingBottom="5dp"
android:scrollbars="none" >
<LinearLayout
android:id="@+id/innerLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:layout_width="match_parent"
android:layout_height="700dp"
android:background="@android:color/transparent"
android:scaleType="fitXY"
android:src="@drawable/image2" />
</LinearLayout>
</ScrollView>
</LinearLayout>
你写了xml属性android:layout_alignParentBottom =“true”所以你的ScrollView总是会对齐底部。
删除android:layout_alignParentBottom =“true”,然后重试。
您可以使用
android:layout_marginTop="10dip"
要么
android:layout_marginBottom="20dip"
这是为了在顶部和底部具有(5dp)空间
<ScrollView
android:id="@+id/scrollView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/backgroundView1"
android:fadingEdge="none"
android:scrollbars="none"
android:paddingTop="5dp"
android:paddingBottom="5dp">
<RelativeLayout
android:id="@+id/innerLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp">
</RelativeLayout>
</ScrollView>
这是为了在顶部,底部,左侧和右侧具有(5 dp)空间
<ScrollView
android:id="@+id/scrollView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/backgroundView1"
android:fadingEdge="none"
android:scrollbars="none"
android:paddingTop="5dp"
android:paddingBottom="5dp">
<RelativeLayout
android:id="@+id/innerLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp">
</RelativeLayout>
</ScrollView>