省略号的设置:
在xml中为TextView设置属性

android:ellipsize = “end”   省略号在结尾

android:ellipsize = “start”   省略号在开头

android:ellipsize = “middle” 省略号在中间

android:ellipsize = “marquee” 跑马灯

使用注意:
有时需要与lines属性和Singleline结合使用才能有效。

xml中设置

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lines="2"
android:ellipsize="end"
android:text="@string/content"
<Button
android:id="@+id/button_show"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="显示更多内容"
android:layout_gravity="bottom"/>

</LinearLayout>
</ScrollView>
</LinearLayout>

MainActivity中进行点击事件的处理

public class TestText extends AppCompatActivity
private TextView mTextView;
private Button mButton;
private boolean flag;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.testlayout);
mTextView= (TextView) findViewById(R.id.textview);
mButton= (Button) findViewById(R.id.button_show);
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(!flag){
//不设置省略号
mTextView.setEllipsize(null);
//使得lines属性失效
mTextView.setSingleLine(false);
flag=true;
mButton.setText("隐藏展开内容");
}else{
//设置结尾处进行省略
mTextView.setEllipsize(TextUtils.TruncateAt.END);
mTextView.setSingleLine(false);
mTextView.setLines(2);
mButton.setText("显示全部内容");
flag=false;
}

}
});
}

}