Android development experience 2

Source: Internet
Author: User

1. ellipsize of TextView
We all know that when ellipsize is set in TextView, the displayed results will be scaled down, but it is worse
By default, Google only displays rows of rows. If you want to display more lines, you must customize TextView.
During the process of repetitive work, I paste this part of the code in the recent project, as shown below:
[Java]
Package com. hustunique. Fuubo. View;
 
Import android. content. Context;
Import android. util. AttributeSet;
Import android. widget. TextView;
 
Public class WeiboContentText extends TextView {
Private String mText;
 
Public WeiboContentText (Context context, AttributeSet attrs ){
Super (context, attrs );
// TODO Auto-generated constructor stub
}
 
Public WeiboContentText (Context context ){
Super (context );
// TODO Auto-generated constructor stub
}
 
@ Override
Public CharSequence getText (){
// TODO Auto-generated method stub
Return mText;
}
 
@ Override
Public void setText (CharSequence text, BufferType ){
// TODO Auto-generated method stub
MText = (String) text;
If (mText. length ()> 22 ){
StringBuffer subTextBuffer = new StringBuffer (mText. substring (0, 19 ));
SubTextBuffer. append ("...");
Text = subTextBuffer;
}
Super. setText (text, type );
}
}
Relatively low, but it feels more practical
2. Try the following methods to solve the layout problem after setting the input method to pop-up:
[Java]
GetWindow (). setSoftInputMode (WindowManager. LayoutParams. xxxx );

3. TextView
<TextView
Android: id = "@ + id/xxx"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: scrollbars = "vertical" <! -- Vertical scroll bar -->
Android: singleLine = "false" <! -- Implement multiple rows -->
Android: maxLines = "12" <! -- Up to 12 rows -->
Android: textColor = "# ffffff"
/>
Of course, we also need to use the setMovementMethod method of TextView to set a rolling instance to make TextView move. The Code is as follows:
TextView TV = (TextView) findViewById (R. id. tvCWJ );
TV. setMovementMethod (ScrollingMovementMethod. getInstance ());

4. The use of setInputType in EditText
This method can be used to hide input content, keyboard content, and so on.


From yunqi yunshu

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.