1. 程式人生 > >單行文字,在內容較多的時候,實現左右滑動的方案

單行文字,在內容較多的時候,實現左右滑動的方案

問題描述:

                  在專案中,有時會遇到一個固定行數的文字顯示控制元件。有時我們採用textview來顯示,利用走馬燈來省略過多的內容。但是有時需要單行顯示,多出的內容滑動來檢視。

解決方案:

                 網上看了很多要自定義寫textview的感覺很是繁瑣。自己研究借鑑了一下,決定用edittext來實現。

 <EditText
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_centerVertical="true"
                    android:background="@null"
                    android:textSize="16sp"
                    android:singleLine="true"
                    android:gravity="right"
                    android:drawablePadding="11dp"
                    android:layout_toRightOf="@id/tv_company_label"
                    android:hint="@string/qxb_30_company_hint"
                    android:focusable="false"

~ android:background="@null"     為保證EditText看起來像是TextView,不顯示輸入框的背景,需要設定Edittext的背景為nul

~ android:singleLine="true"設定單行顯示

~android:focusable="false"如果主需要做顯示用,就得設定focusable為flase,注意:不能設定editable為false,不然會使得不能滑動。