Adding blank spaces to layout

Adding blank spaces to layout

Asked on January 9, 2019 in XML.
Add Comment


  • 7 Answer(s)

         To add a specific amount of space simply use Space or View. For example , for 30 vertical density pixels,

    <Space
      android:layout_width="1dp"
      android:layout_height="30dp"/>
    

         If user need a flexible space-filler, then use View between items in a LinearLayout:

    <View
      android:layout_width="1dp"
      android:layout_height="match_parent"
      android:layout_weight="1"/>
    

         else

    <View
      android:layout_width="1dp"
      android:layout_height="0dp"
      android:layout_weight="1"/>
    

         It will works for more layouts for API 14 and later, except the widgets that use FrameLayout instead of that.

    Answered on January 9, 2019.
    Add Comment

         If the user no need the gap to be accurately 2 lines high, then we can add an empty view like,

      <View
        android:layout_width="fill_parent"
        android:layout_height="30dp">
      </View>
    
    Answered on January 9, 2019.
    Add Comment

         View if the user need to change background color , Space if not. That does not term that we need to change view background.

    <View
       android:layout_width="match_parent"
       android:layout_height="20dp"
       android:background="@color/YOUR_BACKGROUND">
    </View>
    

    else Space

    <Space
         android:layout_width="match_parent"
         android:layout_height="20dp"
         />
    
    Answered on January 9, 2019.
    Add Comment
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="\n\n"
    Answered on February 25, 2019.
    Add Comment

    Space is a lightweight View subclass that may be used to create gaps between components in general purpose layouts.

    Answered on February 25, 2019.
    Add Comment
    <View
        android:layout_width="match_parent"
        android:layout_height="20dp"
        android:background="@color/YOUR_BACKGROUND">
    </View>
    Answered on February 25, 2019.
    Add Comment
    <Space
            android:layout_width="match_content"
            android:layout_height="wrap_content"
            android:layout_margin="2sp" />
    Answered on February 25, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.