1. 设置偏移
animalView.setTranslationY(offset);
2. 设置相对顶部居中
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.ALIGN_TOP,view.getId());
animalView.setLayoutParams(layoutParams);
重点:两个view居中对齐的思路
offset = (bigViewHeight - smallViewHeight)/2;
两个view顶部对齐然后,通过这是偏移将中心线对齐
网友评论