Search code examples
androidviewspaceandroid-layout-weight

how to remove space between views in android studio


i want to remove the space between TextView and Button i tried to many options but no one worked for now . thanks in advance and any help will be appreciated . the xml code and preview

this is the code

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.android.myapplication.MainActivity">
<TextView
    android:layout_margin="0dp"
    android:gravity="center"
    android:textColor="#000000"
    android:textSize="33sp"
    android:text="hello"
    android:background="#cc3"
    android:layout_width = "match_parent"
    android:layout_height = "0dp"
    android:layout_weight = "3"/>
<Button
    android:layout_margin="0dp"
    android:layout_width = "match_parent"
    android:layout_weight = "1"
    android:layout_height = "0dp"
    android:text="Click"/>

</LinearLayout>

Solution

  • Add a background color to the button and change the text color accordingly. That way the space will be removed.

    <Button
            android:layout_margin="0dp"
            android:layout_width = "match_parent"
            android:layout_height = "wrap_content"
            android:text="Click"
            android:background="@color/common_google_signin_btn_text_dark_focused"
            android:layout_below="@+id/a"/>
    

    Any custom color will do.

    enter image description here