2015-12-31 13 views
9

Mam obraz EditText z obrazem drawableLeft. Muszę dodać linię pionową w EditText tuż obok mojego drawableLeft jak w poniższym przykładzie:
Android EditText narysuj linię podziału między jej ciągiem a tekstem.

enter image description here

Najłatwiej że mogę myśleć jest dodanie tej linii do mojego rozciągliwej obrazu. Ale ogólnie jest jakiś inny sposób na zrobienie tego?

+1

Wszystkie inne sposoby osiągnięcia tego będą bardziej skomplikowane. Najlepszym sposobem jest dodanie tej linii tylko do rysowania. – priyanka

Odpowiedz

8
  1. Tworzenie prostokątny kształt zaokrąglony narożnik w res/odkształcalne/shape.xml

    <?xml version="1.0" encoding="utf-8"?> 
    <shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <stroke android:width="3dip" android:color="@android:color/darker_gray" /> 
    <corners android:radius="10dip"/> 
    <padding android:left="10dip" android:top="10dip" android:right="10dip"  android:bottom="10dip" /> 
    </shape> 
    
  2. Teraz utworzyć układ

    <?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/shape" 
    android:gravity="center_vertical"> 
    
    
    <ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/imageView" 
    android:src="@drawable/ic_launcher"/> 
    
    <View 
    android:layout_width="2dp" 
    android:layout_height="match_parent" 
    android:background="@android:color/darker_gray" 
    android:layout_marginLeft="10dp"/> 
    
    <EditText 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/editText" 
    android:layout_weight="1" 
    android:background="@null" 
    android:layout_marginLeft="10dp" 
    android:hint="Your bitcoin address here"/> 
    
    
    </LinearLayout> 
    
  3. mam ustawić tło układ liniowy z th prostokątny zaokrąglony kształt narożny. Wygląda dokładnie tak, jak podgląd podglądu urs.

+0

To działa całkowicie. Nigdy nie myślałem o zrobieniu tego w ten sposób. Dzięki – abeikverdi

+0

@abeikverdi: cieszę się, że pomogłeś :) Plz zaakceptuj odpowiedź. – kevz

0

Spróbuj, twój problem rozwiązany

W swojej .xml pliku,

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="5dp" 
     android:background="@drawable/customborder" 
     android:gravity="center|left" 
     android:minHeight="40dip" 
     android:orientation="horizontal" 
     android:padding="5dip" 
     android:weightSum="2"> 

     <LinearLayout 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.2" 
      android:gravity="center" 
      android:orientation="vertical"> 

      <ImageView 
       android:id="@+id/img_clear_to" 
       android:layout_width="30dip" 
       android:layout_height="30dip" 
       android:src="@drawable/ic_action_delete" /> 
     </LinearLayout> 

     <View 
      android:id="@+id/vvv1" 
      android:layout_width="2dp" 
      android:layout_height="match_parent" 
      android:background="@color/colorAccent" /> 

     <LinearLayout 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" 
      android:layout_weight="1.8" 
      android:orientation="vertical"> 

      <TextView 
       android:id="@+id/text_to" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:clickable="true" 
       android:padding="5dip" 
       android:text="@string/text_to" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:textColor="@color/black" 
       android:textSize="@dimen/font_normal_size" /> 
     </LinearLayout> 


    </LinearLayout> 
</LinearLayout> 

customborder.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <corners 
     android:radius="2dp" 
     android:topRightRadius="0dp" 
     android:bottomRightRadius="0dp" 
     android:bottomLeftRadius="0dp" /> 
    <stroke 
     android:width="1dp" 
     android:color="@android:color/black" /> 
</shape> 
3

Można utworzyć layout i attache do editText jako właściwość

android:drawableRight="@android:drawable/your_layout" 

np

<EditText 
    android:width="match_parent" 
    android:drawableLeft="@android:drawable/your_layout" 
/> 

w pliku your_layout.xml można umieścić cokolwiek chcesz.

Proszę sprawdzić this

+0

ah w prawo. Mogę tam przekazać wyciągnięcie. Całkowicie tęsknię za tym! To super. Będzie świetnie, jeśli dodasz prosty kod do pliku your_layout.xml – abeikverdi

0

dość proste!

wystarczy dodać 'FrameLayout'

<FrameLayout 
      android:id="@+id/vertical_divider" 
      android:layout_width="2dp" 
      android:layout_height="48dp" 
      android:layout_toEndOf="@+id/<your_object>" 
      android:layout_toRightOf="@+id/<your_object>" 
      android:background="@color/grey" /> 

Wymień <your_object> z rozciągliwej obrazu.

Powiązane problemy