的TextView的一行文字垂直居中我有一個100dp lineSpacingExtra一個多行編輯文本。如何讓Android中
現在文本顯示在行的頂部。而且光標的高度與線條高度相同,它比文字的高度高得多。
我該如何讓文本顯示在行的中間? 或者如果我可以調整一行文本的填充頂部或填充底部。
注意: 我的意思是不使用android:gravity =「center_vertical」在TextView中使文本中心垂直。 我想在文本行中垂直顯示文本中心。
XML是如下:
<?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" >
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@android:color/transparent"
android:fadingEdge="vertical"
android:gravity="top"
android:inputType="textCapSentences|textMultiLine|textShortMessage"
android:lineSpacingExtra="100dp"
android:longClickable="false"
android:minLines="10"
android:paddingBottom="5dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="5dp"
android:scrollbars="vertical"
android:text="Text ABCDE\n Line2"
android:textAlignment="center"
android:textSize="16sp" />
</LinearLayout>
任何幫助理解。 THX!
張貼您的xml代碼 – Lokesh
在這裏顯示您的xml和快照。 – Piyush
只有EditText沒有辦法,你應該創建一個LinearLayout或RelativeLayout來環繞EditText,將LinearLayout或RelativeLayout的重力設置爲Gravity.Center,將EditText的高度設置爲Wrap_Content,它應該可以工作 –