2015-01-22 20 views
11

Khi tôi chèn văn bản vào trường EditText của mình, văn bản có khoảng cách bất thường giữa chính nó và dòng của EditText. Dưới đây là một màn hình in từ thiết bị đầu cuối của tôi, nơi bạn có thể thấy khoảng cách này tôi đang nói về, nó được đánh dấu màu đỏ. enter image description hereEditText - Khoảng cách giữa văn bản và dòng EditText

Tôi đã chơi xung quanh với căn chỉnh văn bản và trọng lực nhưng không thành công.

Đây là XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:tools="http://schemas.android.com/tools" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:paddingBottom="@dimen/activity_vertical_margin" 
       android:paddingLeft="@dimen/activity_horizontal_margin" 
       android:paddingRight="@dimen/activity_horizontal_margin" 
       android:paddingTop="@dimen/activity_vertical_margin" 
       tools:context=".MainActivity"> 

    <TableLayout 
     android:id="@+id/startJourneyLinearLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:stretchColumns="1"> 

     <TableRow 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 

      <TextView 
       android:id="@+id/startLocationTxtView" 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:layout_column="0" 
       android:layout_gravity="start" 
       android:text="@string/startLocation" 
       android:gravity="center" 
       android:textAppearance="?android:attr/textAppearanceLarge"/> 

      <EditText 
       android:id="@+id/startLocation" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_column="1" 
       android:gravity = "bottom" 
       android:hint="Some text" 
       android:inputType="text"/> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:layout_column="2" 
       android:src="@drawable/my_ic_location"/> 
     </TableRow> 

     <TableRow 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 

      <TextView 
       android:id="@+id/endLocationTxtView" 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:layout_column="0" 
       android:layout_gravity="start" 
       android:gravity="center" 
       android:text="@string/endLocation" 
       android:textAppearance="?android:attr/textAppearanceLarge"/> 

      <EditText 
       android:id="@+id/endLocation" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_column="1" 
       android:inputType="text"/> 
     </TableRow> 

     <Button 
      android:id="@+id/goButton" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_gravity="center" 
      android:text="@string/go"/> 

    </TableLayout> 

</RelativeLayout> 

Ai đó có thể nhận ra lý do tại sao điều này xảy ra và giải thích cho tôi làm thế nào tôi có thể sửa chữa nó?

--------------- EDIT -----------------------

tôi đã cập nhật mã XML mà tôi đã đăng trong câu hỏi ban đầu lên mã XML thực mà tôi đã sử dụng trong ứng dụng của mình như được yêu cầu trong nhận xét.

Các printscreen đầu tiên (một ở trên, là từ một thiết bị thực -> Galaxy S4 chạy Android 4.4.4 CyanogenMod) và đây là một printscreen từ giả lập sử dụng API 19

enter image description here

+0

là đường màu xanh lục là hình ảnh tùy chỉnh không? –

+0

Không, đó là dòng chữ 'EditText' khi bạn gõ một số văn bản vào đó. – dazito

+0

làm việc tốt của nó trong kết thúc của tôi .. u u thêm bất kỳ mã cho nó cho allignment? –

Trả lời

0

Thử

android:layout_height="wrap_content" 

thay vì

android:layout_height="match_parent" trên EditText của bạn.

+0

Không phải tôi đã downvoted bạn nhưng cả 'EditText' của tôi là' android: layout_height = "match_parent" ' – dazito

0
<EditText 
    android:id="@+id/editTxt1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_column="1" 
    android:layout_gravity = "bottom" 
    android:hint="Some text" 
    android:inputType="text"/> 
+0

Nó không sửa chữa nó. – dazito

+0

ở dưới cùng của hình ảnh edittext. xóa hình ảnh đó. –

+0

Nó cũng không giúp ích gì. – dazito

23

Để thay đổi khoảng cách giữa văn bản EditText và mấu chốt bạn có thể sử dụng android:paddingBottom

<EditText 
     android:id="@+id/nameEditText" 
     style="@style/DarkEditText" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:hint="@string/name" 
     android:paddingBottom="20dp"/> 

Thay paddingBottom giá trị theo yêu cầu của bạn.

Các vấn đề liên quan