Android UI realizes single line text horizontal touch sliding effect
This example shares the horizontal touch sliding effect of single line text, and realizes the horizontal sliding effect of single line long text in textview through EditText. Next, we will introduce the effect of multi line text folding and expansion, and customize the layout view to realize multi line text folding and expansion.
1. Original intention
In recent applications, textview is used for single line long text. When the text content is too long, you want to achieve the touch horizontal sliding effect. I found a lot online, but I didn't see an effective solution. Among them, the most common and clumsy drop is to rewrite textview and inherit and implement touch and gesture gestures. Personally, I think it's very troublesome.
After being reminded, the simplest solution was found:
Just use EditText directly. Because EditText needs to edit and move the cursor, it can slide horizontally. Therefore, we only need to set it as a transparent background and can't get the focus.
design sketch:
2. Concrete realization
Define EditText and set the background to be transparent. You can't get focus.
android:background=”@android:color/transparent” android:focusable=”false”
(Note: editable = "false" cannot be used because sliding cannot be edited. By using focusable = "false", it cannot be edited and sliding can be performed at the same time)
3. Supplement
In addition, to hide the cursor, just use the settings
Android: cursorvisible = "false" / / hide or
setCursorVisible(false);
Code example:
Attach download address: http://xiazai.jb51.net/201610/yuanma/Androidtouchmove (jb51.net). rar
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.