Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
旋转独立于设置布局,因此视图不';在android中旋转后不适合布局_Android_Animation_Android Relativelayout - Fatal编程技术网

旋转独立于设置布局,因此视图不';在android中旋转后不适合布局

旋转独立于设置布局,因此视图不';在android中旋转后不适合布局,android,animation,android-relativelayout,Android,Animation,Android Relativelayout,我有一个布局,其中有一个带有单个字符的imageView和textView。在某些情况下,此布局是旋转的,但问题是,由于旋转与设置布局无关,因此在某些情况下,textView不能正确地适应布局。我如何解决这个问题 代码如下: RelativeLayout arrowLayout = new RelativeLayout(myLayout.getContext()); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.Lay

我有一个布局,其中有一个带有单个字符的
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);
RelativeLayout arrowLayout=新的RelativeLayout(myLayout.getContext());
RelativeLayout.LayoutParams LayoutParams=新的RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_内容,RelativeLayout.LayoutParams.WRAP_内容);
RelativeLayout.LayoutParams arrowLayoutParams=新的RelativeLayout.LayoutParams(metrics.heightPixels/8,metrics.heightPixels/8);
RelativeLayout.LayoutParams tagLayoutParams=新的RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_内容,RelativeLayout.LayoutParams.WRAP_内容);
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-状态大小/2);
tagLayoutParams.setMargins(metrics.heightPixels/8,0,0,0);
setPivotY(0);
setPivotX(0);
tag.animate().rotation(180f).setDuration(0).start();
如果(x1
其中
图像视图
标记
文本视图


尝试删除此行:
tagLayoutParams.setMargins(metrics.heightPixels/8,0,0)


或者确保“metrics.heightPixels”没有那么大

我不确定我是否理解这个问题,但是,在两个不同的资源文件夹中定义两种不同的布局文件(一种用于横向,一种用于纵向)是否有帮助:布局区域和布局端口?@albertcbraun这不是旋转屏幕的问题。这是关于
animate().rotate()
的问题,这意味着由于一些用户交互,我必须更改imageView和textView的方向。啊。好啊谢谢你帮助我更好地理解这个问题。我在上图中看到的文本有6个字符(a+b)*(不包括空格),但描述中说有一个带有“单个字符”的textview,所以我对此也感到困惑。@albertcbraun箭头下方的textview就是问题所在。如你所见,它是单个字符“a”,但它并不完整;意思是角色的底部不可见我不明白你到底需要什么你能说清楚一点吗