Adding blank spaces to layout

前端 未结 14 1115
深忆病人
深忆病人 2021-01-30 04:53

I am trying to make empty lines within android. This is what I have been doing:

android:layout_width=\"fill_parent\" 
android:layout_height=\"wrap_content\" 
an         


        
相关标签:
14条回答
  • 2021-01-30 05:34

    Use Space or View to add a specific amount of space. For 30 vertical density pixels:

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

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

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

    or

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

    This works for most layouts for API 14 & later, except widgets (use FrameLayout instead).

    [Updated 9/2014 to use Space. Hat tip to @Sean]

    0 讨论(0)
  • 2021-01-30 05:34

    try this

    in layout.xml :

    <TextView
            android:id="@+id/xxx"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="@string/empty_spaces" />
    

    in strings.xml :

    <string name="empty_spaces">\t\t</string>
    

    it worked for me

    0 讨论(0)
  • 2021-01-30 05:38

    Just add weightSum tag to linearlayout to 1 and for the corresponding view beneath it give layout_weight as .9 it will create a space between the views. You can experiment with the values to get appropriate value for you.

    0 讨论(0)
  • 2021-01-30 05:42

    If you don't need the gap to be exactly 2 lines high, you can add an empty view like this:

        <View
            android:layout_width="fill_parent"
            android:layout_height="30dp">
        </View>
    
    0 讨论(0)
  • 2021-01-30 05:42

    This can by be achieved by using space or view.

    Space is lightweight but not much flexible.

    View occupies a rectangular area on the screen and is responsible for drawing and event handling. View is more customizable, you can add background, draw shapes like space.

    Implementing Space :

    (Eg: Space For 20 vertical and 10 horizontal density pixels)

    <Space
      android:layout_width="10dp"
      android:layout_height="20dp"/>
    

    Implementing View :

    (Eg: View For 20 vertical and 10 horizontal density pixels including a background color)

      <View
           android:layout_width="10dp"
           android:layout_height="20dp"
           android:background="@color/bg_color"/>
    

    Space for string formatting using HTML entity:

    &#160; for non-breakable whitespace. &#032; for regular space.

    0 讨论(0)
  • 2021-01-30 05:43

    I strongly disagree with CaspNZ's approach.

    First of all, this invisible view will be measured because it is "fill_parent". Android will try to calculate the right width of it. Instead, a small constant number (1dp) is recommended here.

    Secondly, View should be replaced by a simpler class Space, a class dedicated to create empty spaces between UI component for fastest speed.

    0 讨论(0)
提交回复
热议问题