0

No matter what I do my EditText appears like this :

enter image description here

My XML :

<android.support.design.widget.TextInputLayout
    android:id="@+id/text_input_layout_search"               
    android:layout_width="wrap_content"
    android:layout_weight="1"
    android:layout_gravity="top"
    android:gravity="top"                
    android:layout_height="wrap_content">
    <EditText
         android:background="@null"
         android:textColor="@color/black"
         android:layout_centerInParent="true"
         android:gravity="top"
         android:layout_gravity="top"
         android:id="@+id/SearchText"
         android:textColorLink="@color/black"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:textColorHint="@color/normatext"
     android:inputType="text"/>
 </android.support.design.widget.TextInputLayout>

I changed all possible values for gravity and layout_gravity in every possible variation! Any ideas ?

EDIT : Full Layout :

 <LinearLayout
        android:layout_width="match_parent"
        android:orientation="horizontal"
        android:layout_marginTop="0dp"
android:paddingTop="6dp"
        android:paddingBottom="5dp"
        android:layout_margin="3dp"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:layout_height="45dp">
        <Button
            android:layout_width="43dp"
            android:layout_height="wrap_content"
            android:background="@drawable/ham"
            android:id="@+id/hambtn"
            android:textColorHint="@color/black"
            android:layout_weight="0"
            />
        <android.support.design.widget.TextInputLayout
    android:id="@+id/text_input_layout_search"               
    android:layout_width="wrap_content"
    android:layout_weight="1"
    android:layout_gravity="top"
    android:gravity="top"                
    android:layout_height="wrap_content">
    <EditText
         android:background="@null"
         android:textColor="@color/black"
         android:layout_centerInParent="true"
         android:gravity="top"
         android:layout_gravity="top"
         android:id="@+id/SearchText"
         android:textColorLink="@color/black"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:textColorHint="@color/normatext"
     android:inputType="text"/>
 </android.support.design.widget.TextInputLayout>
        <Button
            android:layout_width="55dp"
            android:layout_weight="0"
            android:layout_height="match_parent"
            android:background="@drawable/my_button_bg"
            android:text="news"
            android:id="@+id/newsbtn"
         android:layout_marginLeft="8dp"
            android:layout_marginRight="6dp"
            android:paddingBottom="5dp"
            />
    </LinearLayout>
Arvin Sanaei
  • 103
  • 1
  • 12

3 Answers3

0

Never had this problem before but i would make sure explicitly that there is no padding in the parent and no margin in the child. i.e.:

<android.support.design.widget.TextInputLayout
    ...
    android:padding="0dp" 
>

    <EditText
        ...
        android:layout_margin="0dp"
    />

</android.support.design.widget.TextInputLayout>
Re'em
  • 1,869
  • 1
  • 22
  • 28
0

Can You remove the background tag of EditText and reply me if it works or not ? Also provide your full layout file for exact solution.

Anuj Kumar
  • 1,092
  • 1
  • 12
  • 26
0

I think the problem is maybe in your topmost LinearLayout view.

Try removing those lines:

android:layout_marginTop="0dp"
android:paddingTop="6dp"
android:paddingBottom="5dp"
android:layout_margin="3dp"

and add those lines instead to make sure there are no padding and margin at all:

android:padding="0dp"
android:layout_margin="0dp"

If it did solve the problem, you can go ahead and read more about padding and margin here. If not, I would suspect that your TextInputLayout gets confused because of the inner EditText asking it to be both top and center. remove the "center" part (e.g. remove this - android:layout_centerInParent="true" from your EditText) and check if it solves your issue :)

Re'em
  • 1,869
  • 1
  • 22
  • 28