3

When placing an EditText view next to a TextView in android, you can align it to the baseline of the TextView. Is there a way to reduce the space between the baseline and the actual bottom (the black line at the bottom of the EditText)?

This is the problem

I don't want the black line to go downwards either.I just want the space between the thext "0" and the black baseline at the bottom to shrink.

This is the xml code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/container"
android:layout_width="match_parent" android:layout_height="match_parent"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:background="@color/primary">
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Route distance: "
    android:id="@+id/RouteDistanceLabel"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginLeft="10dp"
    android:layout_marginStart="10dp"
   android:layout_marginTop="10dp"

/>

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="0"
    android:id="@+id/textViewDistance"
    android:layout_toRightOf="@+id/RouteDistanceLabel"
    android:layout_alignTop="@id/RouteDistanceLabel"
    android:layout_alignBaseline="@id/RouteDistanceLabel"
    android:layout_alignBottom="@id/RouteDistanceLabel"
    android:gravity="center_vertical"
/>
</RelativeLayout >
kdlannoy
  • 103
  • 1
  • 8

1 Answers1

2

You can follow my answer and customize it as per you requirement

  <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Route distance: "
        android:id="@+id/RouteDistanceLabel"
        android:layout_alignBottom="@+id/textViewDistance"
        android:layout_alignTop="@+id/textViewDistance"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginLeft="10dp"
        android:layout_marginStart="10dp"
        android:layout_marginTop="10dp"

        />

    <EditText

        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="0efghnm"
        android:textSize="20dp"
        android:textColor="@android:color/black"
        android:id="@+id/textViewDistance"
        android:layout_toRightOf="@+id/RouteDistanceLabel"
        android:gravity="center_vertical" />

Use android:paddingTop="Xdp" in your EditText to bring them to same line. and use android:paddingBottom="0dp" to close all the gap bettwenn edittext line and text. ( Change it as per your requirement)

Kunu
  • 5,078
  • 6
  • 33
  • 61
  • As this helped to bring the baseline to the aligned bottom of the textview, the space between the baseline and the bottom of the textview remains the same, so i get the problem described in my edited question. – kdlannoy Apr 11 '15 at 10:03
  • use paddingBottom if you want it give some space in bottom of your textView – Kunu Apr 11 '15 at 10:06
  • Once i do that, i get the same problem as before. Maybe i didn't explain clearly enough. I have a TextView, next to it i have an EditText. The edittext is aligned at the bottom to the textview (left of it). I want to shrink the space between the baseline and the bottom of the editText. – kdlannoy Apr 11 '15 at 10:09
  • @kdlannoy please check my edited answer. I have edited your xml code. – Kunu Apr 11 '15 at 10:10
  • when using your code, i get this as a result: [result](http://i.imgur.com/uyDn8rg.png). What i actually want is: [wanted](http://i.imgur.com/MY5UENF.png) – kdlannoy Apr 11 '15 at 10:48
  • 1
    yes for that use `android:paddingBottom="0dp"` in you edittext – Kunu Apr 11 '15 at 10:59
  • android:paddingTop="10dp" and android:paddingBottom="0dp" worked for me. – V_J Aug 10 '15 at 07:47
  • I dont know why this answer is accepted paddingBottom doesnt clear the baseline – user3701188 Mar 01 '19 at 09:00