Textview点击加载全部,再次点击收回
上图是加载全部之前的
这是加载全部的,写的代码都是简单易懂的。
xml中的两个Textview
<TextView
android:id="@+id/tv_shop_storeIntroduce"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_10"
android:maxLength="5000"
android:singleLine="false"
android:lines="3"
android:ellipsize="end"
android:text="文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍" />
android:maxLength="100"
android:scrollHorizontally="false"/>
<TextView
android:layout_gravity="center_horizontal"
android:padding="@dimen/dp_10"
android:id="@+id/tv_load"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="加载更多"
android:drawablePadding="@dimen/dp_5"
android:drawableRight="@drawable/shop_more_arrow"
android:singleLine="true"/>
Java代码:
private boolean mapboolean = true;
case R.id.tv_load://点击事件
if (mapboolean) {
//加载全部的状态
mapboolean = false;
Drawable draw = getResources().getDrawable(R.drawable.shop_more_arrow);
mTvload.setCompoundDrawablesRelativeWithIntrinsicBounds(null,null,draw,null);
mTvload.setText("收起");
mTvshopstoreIntroduce.setEllipsize(null); // 展开
mTvshopstoreIntroduce.setSingleLine(mapboolean);
mTvshopstoreIntroduce.setEllipsize(TextUtils.TruncateAt.END);//以...的形式显示多余的
} else {
// 收缩后的状态
mapboolean = true;
Drawable draw = getResources().getDrawable(R.drawable.shop_down_xia);
mTvload.setCompoundDrawablesRelativeWithIntrinsicBounds(null,null,draw,null);
mTvshopstoreIntroduce.setLines(3);
mTvshopstoreIntroduce.setEllipsize(TextUtils.TruncateAt.END);
mTvload.setText("加载更多");
}
break;
我自己作为记录的内容:优化之后的:
<TextView
android:id="@+id/tv_load"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_gravity="center_horizontal"
android:drawablePadding="@dimen/dp_8"
android:drawableRight="@drawable/shop_arrow_down"
android:padding="@dimen/dp_10"
android:text="加载更多"
android:visibility="gone" />
mTvload.setVisibility(mTvshopstoreIntroduce.getText().toString().length() > 63 ? View.VISIBLE : View.GONE);//是否显示加载更多,超过多少文字进行显示按钮。什么都没有就隐藏。mTvshopstoreIntroduce获取接口内容。
case R.id.tv_load:
if (mapboolean) {
//加载全部的状态
mapboolean = false;
Drawable draw = getResources().getDrawable(R.drawable.shop_arrow_up);
mTvload.setCompoundDrawablesRelativeWithIntrinsicBounds(null, null, draw, null);
mTvload.setText("收起");
mTvshopstoreIntroduce.setEllipsize(null); // 展开
mTvshopstoreIntroduce.setSingleLine(mapboolean);
mTvshopstoreIntroduce.setEllipsize(TextUtils.TruncateAt.END);//以...的形式显示多余的
} else {
// 收缩后的状态
mapboolean = true;
Drawable draw = getResources().getDrawable(R.drawable.shop_arrow_down);
mTvload.setCompoundDrawablesRelativeWithIntrinsicBounds(null, null, draw, null);
mTvshopstoreIntroduce.setLines(3);
mTvshopstoreIntroduce.setEllipsize(TextUtils.TruncateAt.END);
mTvload.setText("加载更多");
}
break;