Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1050376
  • 博文数量: 403
  • 博客积分: 10272
  • 博客等级: 上将
  • 技术积分: 4407
  • 用 户 组: 普通用户
  • 注册时间: 2012-02-24 14:22
文章分类

全部博文(403)

文章存档

2012年(403)

分类: 嵌入式

2012-03-01 17:41:56

1.TextView的ellipsize

我们都知道当在TextView中设定ellipsize时,显示的结果会是缩略显示,但是比较不好的是

Google默认只会显示倆行,如果自己想多显示的话就必须自定义TextView,为了减少开发

过程中的重复工作,我把最近做的项目中的这部分代码贴出来,如下:

  1. package com.hustunique.Fuubo.View;  
  2.   
  3. import android.content.Context;  
  4. import android.util.AttributeSet;  
  5. import android.widget.TextView;  
  6.   
  7. public class WeiboContentText extends TextView{  
  8.     private String mText;  
  9.   
  10.     public WeiboContentText(Context context, AttributeSet attrs) {  
  11.         super(context, attrs);  
  12.         // TODO Auto-generated constructor stub  
  13.     }  
  14.   
  15.     public WeiboContentText(Context context) {  
  16.         super(context);  
  17.         // TODO Auto-generated constructor stub  
  18.     }  
  19.   
  20.     @Override  
  21.     public CharSequence getText() {  
  22.         // TODO Auto-generated method stub  
  23.         return mText;  
  24.     }  
  25.   
  26.     @Override  
  27.     public void setText(CharSequence text, BufferType type) {  
  28.         // TODO Auto-generated method stub  
  29.         mText = (String) text;  
  30.         if (mText.length()>22) {  
  31.             StringBuffer subTextBuffer = new StringBuffer(mText.substring(019));  
  32.             subTextBuffer.append("...");  
  33.             text = subTextBuffer;  
  34.         }   
  35.         super.setText(text, type);  
  36.     }  
  37. }  
比较低级,但是感觉还是比较实用

2.设置输入法弹出后的布局问题可以试下以下系列方法:

  1. getWindow().setSoftInputMode(WindowManager.LayoutParams.xxxx);  

3.TextView实现多行本文滚动 
 
    android:id="@+id/xxx"  
    android:layout_width="fill_parent"  
    android:layout_height="wrap_content"  
    android:scrollbars="vertical"    
    android:singleLine="false"        
    android:maxLines="12"             
    android:textColor="#ffffff" 
    /> 
   当然我们为了让TextView动起来,还需要用到TextView的setMovementMethod方法设置一个滚动实例,代码如下 
TextView tv = (TextView)findViewById(R.id.tvCWJ);   
tv.setMovementMethod(ScrollingMovementMethod.getInstance()); 

4.EditText中setInputType的妙用

使用该方法我们可以实现诸如隐藏/显示输入内容,隐藏键盘等等


阅读(484) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~