Android 中的 MultiLine EditText 光标从顶部开始

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10503668/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 03:58:23  来源:igfitidea点击:

MultiLine EditText in Android with the cursor starting on top

androidandroid-layoutandroid-edittext

提问by Keyser Sozé

I know it seems it's an already thousand times answered issue but I haven't found anything that works for me.

我知道这似乎是一个已经回答了数千次的问题,但我还没有找到任何对我有用的东西。

I have a MultiLine EditText on Android that adapts to the view size by "playing" with the weight (1) and the height (0dip). I am using gravity "top" but it starts in the middle.

我在 Android 上有一个 MultiLine EditText,它通过“播放”重量 (1) 和高度 (0dip) 来适应视图大小。我使用重力“顶部”,但它从中间开始。

I guess the problem it's related with the weight. Here's the code (the parent is a LinearLayout):

我想问题与重量有关。这是代码(父级是 LinearLayout):

    <EditText
        android:id="@+id/txtContacto"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_gravity="top"
        android:inputType="textMultiLine" 
        android:weight="1">
    </EditText>

回答by Shankar Agarwal

<EditText
        android:id="@+id/txtContacto"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:gravity="top"
        android:inputType="textMultiLine" 
        android:weight="1">
    </EditText>

try the above code.. where layout gravity sets the edittext and gravity sets the content of edittext.

试试上面的代码..其中布局重力设置edittext,重力设置edittext的内容。