2016-09-18 3 views
0

ich von this answer eine benutzerdefinierte EditText bin Gebäude, das ist die Ausgabe erhalte ich,Benutzerdefinierte EditText zeigt keine Linien über

enter image description here Problem Die Linien sind nicht ganz oben beginnen, sie beginnen, irgendwo in die Mitte, was könnte falsch sein.

Hier ist der Code,

public class LinedEditText extends EditText { 

    private static Paint linePaint; 

    static { 
     linePaint = new Paint(); 
     linePaint.setColor(Color.BLACK); 
     linePaint.setStyle(Paint.Style.STROKE); 
    } 

    public LinedEditText(Context context, AttributeSet attributes) { 
     super(context, attributes); 
    } 

    @Override 
    protected void onDraw(Canvas canvas) { 
     Rect bounds = new Rect(); 
     int firstLineY = getLineBounds(0, bounds); 
     int lineHeight = getLineHeight(); 
     int totalLines = Math.max(getLineCount(), getHeight()/lineHeight); 

     for (int i = 0; i < totalLines; i++) { 
      int lineY = firstLineY + i * lineHeight; 
      canvas.drawLine(bounds.left, lineY, bounds.right, lineY, linePaint); 
     } 

     super.onDraw(canvas); 
    } 
} 

Hier ist meine XML,

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

    <TextView 
     android:layout_width="match_parent" 
     android:gravity="center" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:text="Large Text" 
     android:id="@+id/textView" 
     android:padding="8dp" 
     android:layout_margin="10dp" 
     android:background="@drawable/shape" 
     android:layout_gravity="center_horizontal" /> 



    <com.random.simplenotes.LinedEditText 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 

     /> 


</LinearLayout> 

Antwort

0

Alles, was ich war die Schwere und alles war in Ordnung,

<com.random.simplenotes.LinedEditText 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:inputType="textMultiLine" 
     android:gravity="top|left" 
     /> 
tat hinzugefügt
Verwandte Themen