简体   繁体   中英

android:alignment of text in edittext

I am making an app in which i have to use edit text and when i use this text on samsung galaxy s and emulator , the text starts from center of edittext rather than starting from top.The screen shot and code is as follows`

 <EditText android:id="@+id/tester" 
     android:layout_height="113dip" 
     android:layout_width="420dip" 
     android:background="@drawable/textarea_reason" 
     android:paddingTop="-90dip"/>

当我在编辑文本中输入文本时,它从一些间隙开始而不是从顶部开始 `

You need to change gravity parameter.

Java Code

editText.setGravity(Gravity.TOP| Gravity.LEFT); 

XML

<EditText 
    android:id="@+id/tester" 
    android:layout_height="113dip" 
    android:layout_width="420dip" 
    android:background="@drawable/textarea_reason" 
    android:gravity="top|left"/>

Update yor Edit Text tag like as...

<EditText 
    android:id="@+id/tester" 
    android:layout_height="113dip" 
    android:layout_width="420dip" 
    android:background="@drawable/textarea_reason" 
    android:gravity="top|left"/>

你已经设置了背景图像,这就是为什么会出现这个问题,把android:paddingLeft =“20dp”和测试

尝试将xml或minLines中的编辑文本属性singleLine="false" minLines为> 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM