How do I place the text inside an EditText widget at the top?

江枫思渺然 提交于 2019-12-10 12:49:04

问题


I have the following xml for an edittext and button which take the whole screen. The only problem is I can't find a way to make the typed text in the edittext to be put at the top. Right now it's put in the centre of the editText.

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



        <EditText
            android:id="@+id/invoerTekst"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:hint="@string/prompt_tekst" />

        <Button
            android:id="@+id/klaar"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:text="@string/action_sla_op"
            android:background="@drawable/main_button_over"
            android:textColor="#ffffff"
            android:layout_margin="5dip"
            android:layout_below="@id/invoerTekst" />



    </LinearLayout>

回答1:


Add android:gravity="top" attribute to your EditText.




回答2:


Use this, It will help you.

EditText

    android:id="@+id/invoerTekst"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:gravity="top"
    android:hint="@string/prompt_tekst" 


来源:https://stackoverflow.com/questions/5832388/how-do-i-place-the-text-inside-an-edittext-widget-at-the-top

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!