Java Android活动内容视图大小
如果你搜索,会有很多问题。 答案显示屏幕的宽度/高度。不需要 我需要图像视图的可用空间:白色背景的汽车。如何获得它? 我不需要顶部装饰栏,也不需要底部/右侧菜单栏,也不需要整个屏幕大小,包括时间、电池 以下是我迄今为止所尝试的:Java Android活动内容视图大小,java,android,android-activity,Java,Android,Android Activity,如果你搜索,会有很多问题。 答案显示屏幕的宽度/高度。不需要 我需要图像视图的可用空间:白色背景的汽车。如何获得它? 我不需要顶部装饰栏,也不需要底部/右侧菜单栏,也不需要整个屏幕大小,包括时间、电池 以下是我迄今为止所尝试的: public class MainActivity extends Activity { private SVGImageView svgImageView; @Override protected void onCreate(Bundle
public class MainActivity extends Activity {
private SVGImageView svgImageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
svgImageView = new SVGImageView(this);
svgImageView.setImageAsset("my.svg");
// Set the ImageView as the content view for the Activity
setContentView(svgImageView);
}
@Override
protected void onPostResume() {
super.onPostResume();
int w = getWindow().getDecorView().getWidth();
int h = getWindow().getDecorView().getHeight();
Log.d("DisplayMetrics","w2:"+w+", h2:"+h);// 0 and 0
}
@Override
protected void onStart() {
super.onStart();
DisplayMetrics metrics = getResources().getDisplayMetrics();
int width = metrics.widthPixels;
int height = metrics.heightPixels;
//int bottom = svgImageView.getBottom();
int w = svgImageView.getWidth();//0
int h = svgImageView.getHeight();//0
Log.d("DisplayMetrics", "width: "+width+ ", height:"+height+", w:"+w+", h:"+h);
// landscape: 1280 x 752. Real 1280x700
// portrait: 800 x 1232. Real 800x1177
}
SVGImageView是ImageView的子产品。如果有人感兴趣,请详细介绍SVG。公认的答案应给出与此相同的宽度和高度:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
svgImageView = new SVGImageView(this){
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int canvasH = canvas.getHeight();
int canvasW = canvas.getWidth();
Log.d("DisplayMetrics", "canvasW:"+canvasW + ", canvasH: "+canvasH);// Portrait 800 x 1176, Landscape 1280 x 696,
}
我正在检查电话号码
我认为mWindow将拥有所需的数据。问题是何时和如何获得它
不幸的是,这是一个:
但是在新的SVGImageView(这个)中覆盖onSizeChanged
,我将在那里正确地获得数字
现在是我的实施:
// This is the top-level view of the window, containing the window decor.
private DecorView mDecor;
// This is the view in which the window contents are placed. It is either
// mDecor itself, or a child of mDecor where the contents go.
private ViewGroup mContentParent;
private final class DecorView extends FrameLayout implements RootViewSurfaceTaker
我的通话记录:
myActivity.onPostResume()
myContentView.onSizeChanged()
myContentView.onDraw();
=>需要订阅布局侦听器或覆盖顶部组件onSizeChanged
// This is the top-level view of the window, containing the window decor.
private DecorView mDecor;
// This is the view in which the window contents are placed. It is either
// mDecor itself, or a child of mDecor where the contents go.
private ViewGroup mContentParent;
private final class DecorView extends FrameLayout implements RootViewSurfaceTaker
myActivity.onPostResume()
myContentView.onSizeChanged()
myContentView.onDraw();