我有一个布局,其中有imageView
和textView
一个字符。在某些情况下,此布局会旋转,但问题是由于旋转与设置布局无关,因此textView
不适合布局。我该如何解决这个问题?
这里的代码:
RelativeLayout arrowLayout = new RelativeLayout(myLayout.getContext());
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
RelativeLayout.LayoutParams arrowLayoutParams = new RelativeLayout.LayoutParams(metrics.heightPixels / 8, metrics.heightPixels / 8);
RelativeLayout.LayoutParams tagLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
float x1 = origin.getLeft() + origin.getWidth() / 2, y1 = origin.getTop() + origin.getHeight() / 2;
int stateSize = origin.getWidth();
layoutParams.leftMargin = (int) (x1 - stateSize * 3 / 2);
layoutParams.topMargin = (int) (y1 - stateSize / 2);
tagLayoutParams.setMargins(metrics.heightPixels / 8, 0, 0, 0);
setPivotY(0);
setPivotX(0);
tag.animate().rotation(180f).setDuration(0).start();
if (x1 < metrics.widthPixels * 3 / 20) {
if (metrics.heightPixels - y1 < metrics.widthPixels * 3 / 20) {
arrowLayout.animate().rotation(270f).translationX(stateSize).translationY(-stateSize).setDuration(0).start();
tag.animate().rotation(90f).setDuration(0).start();
}
else {
arrowLayout.animate().rotation(90f).translationX(stateSize).translationY(stateSize).setDuration(0).start();
tag.animate().rotation(-90f).setDuration(0).start();
}
}
else {
arrowLayout.animate().rotation(180f).setDuration(0).start();
}
arrowLayout.addView(tag, tagLayoutParams);
arrowLayout.addView(this, arrowLayoutParams);
myLayout.addView(arrowLayout, layoutParams);
其中this
是imageView
而tag
是textView
。
答案 0 :(得分:-1)
尝试删除此行:tagLayoutParams.setMargins(metrics.heightPixels / 8, 0, 0, 0);
或者确保&#34; metrics.heightPixels&#34;不是那么大。