why marginBottom not working?
marginBottom
has no effect if you set android:layout_height="wrap_content"
for <RelativeLayout>
, instead set it as match_parent and check.
It is realy just a bug of the <RelativeLayout>
, so you could try to wrap the RelativeLayout inside of a <LinearLayout>
and set the margin there.
I am not sure in which revision of android you are experiencing this issue. I looked at RelativeLayout in Android 4.2.2 (https://android.googlesource.com/platform/frameworks/base/+/android-4.2.2_r1.1/core/java/android/widget/RelativeLayout.java) and I believe there is a bug in the onMeasure.
In lines 486 to 488, we have following code:
if (isWrapContentHeight) {
height = Math.max(height, params.mBottom);
}
In my opinion, the above should read:
if (isWrapContentHeight) {
height = Math.max(height, params.mBottom + params.bottomMargin);
}
With android:layout_height="wrap_content", RelativeLayout does not appear take into account the bottomMargin of the last vertically laid out view.
I suggest you try one of the following:
*) Add a dummy view that will be the very last vertically laid out view, and ensure that it has the android:layout_below attribute. Note that the dummy view does not have a bottom margin, it is there so that RelativeLayout considers the bottom margin of views laid out above it. For your case, the dummy view would look like this:
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="@id/messageSender"
/>
*) As others have mentioned, achieve the same effect in other ways, such as Padding.
*) A not-so-trivial solution is bring in RelativeLayout, its platform style definitions and Pool management classes into your project, perform the bug fix I mentioned above and use this anywhere you would normally use RelativeLayout.
*) File a bug with Google
Hope this helps.
Maybe you can set android:paddingBottom=""
of <RelativeLayout>
to get the same effect.
Make sure the layout_height
of your root container is set to match_parent
instead of wrap_content
.