EditText 幾種顯示方式,固定行數,自適應行數


1.顯示7行,超過7行自動向下補充行數

  <EditText
    android:id="@+id/edt_content"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/white"
    android:gravity="left|top"
    android:hint="請輸入作業內容"
    android:inputType="textMultiLine"  <!--設置可以多行-->
    android:maxLength="800"    <!-- 限制最大可輸入字符數 -->
    android:minLines="7"          <!-- 初始化時顯示的是7行 -->
    android:padding="10dp"     
    android:paddingLeft="10dp"
    android:textSize="14sp" />

 

 

 2.自動滾動條,並顯示最新內容

  <EditText

    android:id="@+id/edt_content"
    android:layout_width="fill_parent"
    android:layout_height="260px"
    android:textColor="#000000"
    android:padding="5px"
    android:scrollbars="vertical"  <!--垂直滾動條-->
    android:singleLine="false"    <!--多行-->
    android:maxLines="14"       <!--最多顯示14行-->
    android:focusable="false"
    android:clickable="true"
    android:background="#ff87CEEB"
   />

  要在Java代碼中設置滾動的方法( EditText mEdtContent ):

  mEdtContent.setMovementMethod(ScrollingMovementMethod.getInstance());

  下面是設置顯示最新的內容:

  mEdtContent.setSelection(chatsView.getText().length(), chatsView.getText().length());


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM