应用详情界面
在oncreate()方法中设置布局监听 为了获取应用简介文本的初始高度
//给desc设置布局改变监听器 当onLayout方法执行的时候就会执行这个监听
tv_desc.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
//获取图片的高度
descDefaultHeight = tv_desc.getHeight();
System.out.println("--------------" +descDefaultHeight);
if (descDefaultHeight > 0) {
tv_desc.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
}
});
点击安全无广告按钮布局时的打开和关闭事件
private void safeDisplayToggle() {
//测量下描述d
ll_safe_desc.measure(0, 0);
int original =ll_safe_desc.getMeasuredHeight();//获取测量的高
ValueAnimator valueAniator;
if (safeIsOpen) {//是打开状态 ---->关闭
valueAniator = ValueAnimator.ofInt(original,0);
//箭头变换
iv_safe_arrow.setImageResource(R.drawable.arrow_down);
}else {//关闭状态 ------>打开
valueAniator = ValueAnimator.ofInt(0,original);
//箭头变换
iv_safe_arrow.setImageResource(R.drawable.arrow_up);
}
safeIsOpen = !safeIsOpen;
//
valueAniator.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
//将value设置给desc的高的
ll_safe_desc.getLayoutParams().height = (Integer) animation.getAnimatedValue();
//属性layout
ll_safe_desc.requestLayout();
}
});
valueAniator.setDuration(200);
valueAniator.start();
}
展示应用简介 打开和关闭
//应用简介的缩放开关
private void descDisplayToggle() {
//获取展开后的总高度
int totalHeight = getTotalHeight();
final ValueAnimator value;
if (descIsOpen) {//打开状态 ----->关闭
value = ValueAnimator.ofInt(totalHeight,descDefaultHeight);
iv_desc_arrow.setImageResource(R.drawable.arrow_down);
}else {//关闭状态 ------>打开
value = ValueAnimator.ofInt(descDefaultHeight,totalHeight);
iv_desc_arrow.setImageResource(R.drawable.arrow_up);
}
descIsOpen = !descIsOpen;
//刷新value
value.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
tv_desc.getLayoutParams().height = (Integer) animation.getAnimatedValue();
//更新layout
tv_desc.requestLayout();
//ScrollView直接滚动value的数字
scroll_view.scrollBy(0, (Integer) animation.getAnimatedValue());
}
});
value.setDuration(200);
value.start();
}
应用截图
布局
<!-- 第三块:应用截图 -->
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#CCCCCC">
<LinearLayout
android:id="@+id/ll_screen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:orientation="horizontal" />
</HorizontalScrollView>
展示应用截图
//展示图片截图
private void showScreen() {
if (appDetailInfo.screen == null || appDetailInfo.screen.isEmpty()) {
return;
}
for (int i = 0; i < appDetailInfo.screen.size(); i++) {
ImageView imageView = new ImageView(AppDetailActivity.this);
int width = UiUtils.dp2px(90);
int height = UiUtils.dp2px(150);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(width, height);
if (i != 0) {
params.leftMargin = UiUtils.dp2px(6);
}
ll_screen.addView(imageView, params );
//下载图片并展示
String picUrl = Urls.IMAGE + "?name=" + appDetailInfo.screen.get(i);
ImageLoader.getInstance().displayImage(picUrl, imageView);
imageView.setTag(i);
//添加点击事件
imageView.setOnClickListener(imageListener);
}
}
OnClickListener imageListener = new OnClickListener() {
@Override
public void onClick(View v) {
int position = (Integer) v.getTag();
//点击图片跳转到大图的activity 并把position 和图片地址传递过去
Intent intent = new Intent(AppDetailActivity.this, BigPictureActivity.class);
intent.putExtra(Keys.POSITION, position);
intent.putStringArrayListExtra(Keys.SCREEN_URLS, appDetailInfo.screen);
startActivity(intent);
}
};
//展示应用简介
private void showDesc() {
tv_desc.setText(appDetailInfo.des);//布局里设置了只显示7行
}
//获取应用简介的总高度
private int getTotalHeight() {
TextView text = new TextView(this);
text.setText(tv_desc.getText());//设置和简介上的文字一样
text.setTextSize(14);//设置和简介上的文字一样大
//System.out.println(tv_desc.getText());
int widthMeasureSpec = MeasureSpec.makeMeasureSpec(tv_desc.getWidth(), MeasureSpec.EXACTLY );
int heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED );
//测量下
text.measure(widthMeasureSpec, heightMeasureSpec);
//获取高度
int totalHeight = text.getMeasuredHeight();
//System.out.println(totalHeight);
return totalHeight;
}