Android 视图/属性转换
当用户向下滚动recyclerview时,我需要进行以下转换,如所附图像所示。“标题A”和“说明”位于RelativeLayout内,将折叠并更改其属性:Android 视图/属性转换,android,animation,android-transitions,Android,Animation,Android Transitions,当用户向下滚动recyclerview时,我需要进行以下转换,如所附图像所示。“标题A”和“说明”位于RelativeLayout内,将折叠并更改其属性: “标题A”从布局\u中心水平=真到布局\u中心垂直=真 “说明”从布局\u中心水平=真到布局\u中心垂直=真,文本大小从30sp到16sp 将相对长度、从70dp到包装内容的高度降至最低 当用户向上滚动并点击顶部时,更改将恢复为原始扩展形式。(这类似于折叠工具栏的概念) 我已经成功地实现了这样一个功能,当我单击一个按钮时,使用view.req
changeLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
animateChanges();
}
});
private void animateChanges() {
ViewGroup.LayoutParams layout = relativeLayout.getLayoutParams();
RelativeLayout.LayoutParams header = (RelativeLayout.LayoutParams) titleA.getLayoutParams();
RelativeLayout.LayoutParams value = (RelativeLayout.LayoutParams) description.getLayoutParams();
// if current is not expanded, we change to expand view
if (!isExpanded) {
relativeLayout.setGravity(Gravity.CENTER);
layout.height = (int) getResources().getDimension(R.dimen.height_60);
header.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
header.addRule(RelativeLayout.ALIGN_PARENT_LEFT, 0);
header.addRule(RelativeLayout.CENTER_VERTICAL, 0);
value.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
value.addRule(RelativeLayout.BELOW, R.id.title_a);
value.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, 0);
value.addRule(RelativeLayout.CENTER_VERTICAL, 0);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
value.addRule(RelativeLayout.ALIGN_PARENT_END, 0);
header.addRule(RelativeLayout.ALIGN_PARENT_START, 0);
}
relativeLayout.setLayoutParams(layout);
titleA.setLayoutParams(header);
description.setLayoutParams(value);
description.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.font_30));
titleA.requestLayout();
description.requestLayout();
relativeLayout.requestLayout();
} else {
relativeLayout.setGravity(Gravity.CENTER_VERTICAL);
layout.height = ViewGroup.LayoutParams.WRAP_CONTENT;
header.addRule(RelativeLayout.CENTER_HORIZONTAL, 0);
header.addRule(RelativeLayout.BELOW, 0);
header.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
header.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
value.addRule(RelativeLayout.CENTER_HORIZONTAL, 0);
value.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
value.addRule(RelativeLayout.BELOW, 0);
value.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
value.addRule(RelativeLayout.ALIGN_PARENT_END, RelativeLayout.TRUE);
header.addRule(RelativeLayout.ALIGN_PARENT_START, RelativeLayout.TRUE);
}
titleA.setLayoutParams(header);
description.setLayoutParams(value);
relativeLayout.setLayoutParams(layout);
description.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.font_16));
relativeLayout.requestLayout();
titleA.requestLayout();
description.requestLayout();
}
isExpanded = !isExpanded;
}
提前谢谢