这可能是一个非常愚蠢的问题,但..
我有3个值,例如我们称之为minX,currentX和maxX.我正在寻找一种方法来计算currentX代表的maxX的百分比.例如,如果maxX为50且minX为40且currentX为45,那么我想得到50%这是非常基本的,但我遇到的问题是当我的一个或多个变量是负数时.
任何帮助将不胜感激,也让我知道,如果我没有充分解释自己
我正在为我当前正在使用的应用程序将mp4流式传输到TextureView。我让TextureView显示视频,但是我需要调整其大小以匹配旋转时的屏幕尺寸。经过多次试验和错误,似乎问题是不能使TextureView大于包含的视图。我也尝试过调整容器视图的大小,但随后无法在屏幕上正确居中TextureView。
public void onOrientationChanged(int orientation) {
if(isLandscape(orientation)){
myTexture.setRotation(-90);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.width = height;
params.height = (height * 9)/16;
params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
myTexture.setLayoutParams(params);
myTexture.getLayoutParams().height = (height * 9)/16;
myTexture.getLayoutParams().width = height;
rl.requestLayout();
rl.invalidate();
rl.recomputeViewAttributes(myTexture);
Log.v("View Size", "Width tex: " + myTexture.getWidth());
Log.v("View Size", "Height tex: " + myTexture.getHeight());
Log.v("View Size", "Width tex parent: " + rl.getWidth());
Log.v("View Size", "Height tex parent : " + rl.getHeight());
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MyActivity"
android:id="@+id/mediaParent"
android:layout_centerInParent="true"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
android:paddingBottom="0dp"> …Run Code Online (Sandbox Code Playgroud)