当前位置:操作系统 > 安卓/Android >>

Android 开发小经验2

1.TextView的ellipsize
我们都知道当在TextView中设定ellipsize时,显示的结果会是缩略显示,但是比较不好的是
Google默认只会显示倆行,如果自己想多显示的话就必须自定义TextView,为了减少开发
过程中的重复工作,我把最近做的项目中的这部分代码贴出来,如下:
[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 type) { 
        // 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); 
    } 

比较低级,但是感觉还是比较实用
2.设置输入法弹出后的布局问题可以试下以下系列方法:
[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"   <!--垂直滚动条 -->
    android:singleLine="false"       <!--实现多行 -->
    android:maxLines="12"            <!--最多不超过12行 -->
    android:textColor="#ffffff"
    />
   当然我们为了让TextView动起来,还需要用到TextView的setMovementMethod方法设置一个滚动实例,代码如下
TextView tv = (TextView)findViewById(R.id.tvCWJ);  
tv.setMovementMethod(ScrollingMovementMethod.getInstance());

4.EditText中setInputType的妙用
使用该方法我们可以实现诸如隐藏/显示输入内容,隐藏键盘等等 


摘自  云卷云舒 
补充:移动开发 , Android ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,