我正在尝试在Android中扩展文本视图,我有一些批量内容的TextView,我的要求是仅显示批量内容中的两行,并完成(... 如果我单击它,则必须显示我的全部内容。 如何实现这一点。你能帮帮我吗?
public class MainActivity extends ActionBarActivity {
TextView t1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
t1 = (TextView) findViewById(R.id.text);
String str = "If your view subclass is displaying its own Drawable objects, it should override this function and return true for any Drawable it is displaying. This allows animations for those drawables to be scheduled." +
"I made the expandable list view acc to your tutorial but what i have to do if I want to populate Expandable List View with values from database?Means what changes I have to do in ";
t1.setText(str);
t1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
t1.setMaxLines(Integer.MAX_VALUE);
}
});
}
}
您可以在布局 xml 中默认将文本视图android:maxLines
属性设置为 2。
在 onCreate() 函数中将文本设置为文本视图 (t1) 后。
添加以下内容
boolean isTextViewClicked = false;
t1.setOnClickListener(new OnClickListener() {
if(isTextViewClicked){
//This will shrink textview to 2 lines if it is expanded.
t1.setmaxLines(2);
isTextViewClicked = false;
} else {
//This will expand the textview if it is of 2 lines
t1.setMaxLines(Integer.MAX_VALUE);
isTextViewClicked = true;
}
});
这将根据内容扩展文本视图