我有一个应用程序,在屏幕的底部有一个工具栏,其余的充满了自定义视图(请参阅下面的xml).现在,当我将应用程序全屏显示时(我尝试了所有可能性,以编程方式并通过Manifest.xml),当它启动时,整个布局似乎向下移动了大约通知栏的高度.工具栏中的按钮仅在中途可见.有时候,所有这些都会在几秒钟之后或者当我单击工具栏中的按钮时向上移动.

我很确定,这是我的自定义视图的问题,因为如果我用Button等替换它,我就不会得到这个效果.我想它必须与该onMeasure方法有关.我真的不知道如何实现它,我的版本如下所示.自定义视图用于绘制内部,因此基本上它希望尽可能大.
任何帮助将非常感激.我已经搜索了几个小时,但还没有任何线索.
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<com.example.MyCanvasView
android:id="@+id/canvas"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<!-- Buttonbar -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="4dp"
android:orientation="horizontal"
android:background="@android:drawable/bottom_bar"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
/>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这是我的onMeasure方法:
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
setMeasuredDimension(width, height);
}
Run Code Online (Sandbox Code Playgroud)
我找到了所描述行为的原因。setFocusableInTouchMode(true)我已通过方法将视图设置为在触摸模式下可聚焦onCreate()。当我删除它后,它就可以正常工作了。不过,多亏了 adamp,您对布局和测量过程中发生的情况的描述非常有趣。
但这给我留下了一个问题,我不再收到任何按键/按钮点击:-(
| 归档时间: |
|
| 查看次数: |
2525 次 |
| 最近记录: |