Reputation: 1226
I am currently using a layout that contains a RelativeLayout inside a ScrollView.
I want the RelativeLayout to be contained 5dp away from the bottom of the ScrollView so it does not overlap the background I have behind it, to achieve this I was using this 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>
This worked perfectly, however I no longer need the padding at the top. When removing the paddingTop line, the paddingBottom no longer functions. Even if I set the paddingBottom to 100dp it shows no effect on my layout.
I tried paddingTop="0dp" and that did not fix the issue either, it seems paddingBottom will only work when paddingTop is above 0.
Anyone got any ideas as to why paddingBottom does not work without paddingTop?
Upvotes: 6
Views: 43574
Reputation: 413
This is for having (5 dp) space on top and bottom
<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>
This is for having (5 dp) space on top, bottom, left, and right
<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>
Upvotes: -1
Reputation: 2040
you can use
android:layout_marginTop="10dip"
or
android:layout_marginBottom="20dip"
Upvotes: 0
Reputation: 52800
You wrote xml property android:layout_alignParentBottom="true" so your ScrollView will always it will be aligned bottom.
Remove android:layout_alignParentBottom="true" and try again.
Upvotes: 0
Reputation: 171
use this kind of layout for scrollview and change according to your need..dont use relative layout inside scrollview. Here you can set any type height in image and still you will see padding at bottom without any 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>
Upvotes: 0