why marginBottom not working?

后端 未结 8 1531
萌比男神i
萌比男神i 2020-12-23 19:47



        
相关标签:
8条回答
  • 2020-12-23 20:08

    In some case you have lots of attributs or you just missed that you included earlier :

    android:layout_margin="xdp"
    

    You can't use it with specific layout margination

    0 讨论(0)
  • 2020-12-23 20:12

    I had a <View> inside a <RelativeLayout> and the marginBottom on that view did not work. I found out that my chain of layout_below was broken, so therefore it makes sense that the layout did not know from which view the margin should be calculated.

    If you chain it properly using layout_below or the other positioning tools, you do not need to worry about wrap_content or match_parent like others are suggesting. Example:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    
        <View
            android:id="@+id/separator"
            android:layout_width="match_parent"
            android:layout_height="1px"
            android:layout_marginBottom="11dp" />
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/separator">
    
            ...
    
    0 讨论(0)
  • 2020-12-23 20:17

    Maybe you can set android:paddingBottom="" of <RelativeLayout> to get the same effect.

    0 讨论(0)
  • 2020-12-23 20:18

    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.

    0 讨论(0)
  • 2020-12-23 20:25

    Make sure the layout_height of your root container is set to match_parent instead of wrap_content.

    0 讨论(0)
  • 2020-12-23 20:30

    It works if you use android:layout_marginBottom with android:layout_alignParentBottom="true".

    For example :

    android:layout_alignParentBottom="true"
    android:layout_marginBottom="50dp">
    
    0 讨论(0)
提交回复
热议问题