Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get rid of extra spacing in LinearLayout?

I've built a widget that uses a LinearLayout and I've put two TextViews in the layout. The gravity of the layout is "top".

The problem is that I get a space between the two TextViews and I can't get rid of it.

    <TextView 
        android:id="@+id/Text01"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:gravity="bottom|center_horizontal" 
        android:text="blah blah"
        android:background="@android:color/transparent"
        android:textColor="#3e6eb4"
        android:textSize="11sp"
        />        

    <TextView 
        android:id="@+id/text02"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:gravity="top|center_horizontal" 
        android:text=""
        android:background="@android:color/transparent"
        android:textColor="#3e6eb4"
        android:textSize="14sp"
        android:padding="0sp"
        android:verticalSpacing="0sp"
        />

As you can see I tried putting padding 0 and verticalSpacing 0 but I still get a space between them.

How can I fix it?

Thanks.

like image 251
Ran Avatar asked Oct 06 '10 08:10

Ran


People also ask

Which is better LinearLayout or RelativeLayout?

LinearLayout is less used as compared to RelativeLayout. RelativeLayout is used more in applications. We can use LinearLayout inside RelativeLayout. We can also use RelativeLayout as a Child of LinearLayout.

What is the difference between RelativeLayout and LinearLayout?

LinearLayout : is a ViewGroup that aligns all children in a single direction, vertically or horizontally. RelativeLayout : is a ViewGroup that displays child views in relative positions. AbsoluteLayout : allows us to specify the exact location of the child views and widgets.

What is RelativeLayout in android?

RelativeLayout is a view group that displays child views in relative positions. The position of each view can be specified as relative to sibling elements (such as to the left-of or below another view) or in positions relative to the parent RelativeLayout area (such as aligned to the bottom, left or center).

What is the use of LinearLayout?

LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally. You can specify the layout direction with the android:orientation attribute. Note: For better performance and tooling support, you should instead build your layout with ConstraintLayout.


1 Answers

You can also try using a negative margin (just like CSS :)

(I did it with my App and it works great)

<TextView
android:layout_marginTop="-10dp"
android:layout_marginBottom="0dp"
/>

Hope this helps!

like image 133
Lior Iluz Avatar answered Oct 13 '22 01:10

Lior Iluz