3

我实际上正在制作一个使用 SurfaceView 绘制相机的 android 应用程序。我想添加一些观点。

事实上,我已经做到了。它适用于我的 android 4.1.1。我所有的视图都绘制在相机上。

但是当我在 Android 2.3 上尝试它时,它不再工作了。取决于我在做什么,它在左上角显示一部分视图(好像父布局太小)

这是xml文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<FrameLayout
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:layout_weight="1">

    <com.example.calculatrice.CustomCameraView
        android:id="@+id/cameraView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/poiGroup">
        <Button
            android:id="@+id/bBack"
            android:layout_width="150dp"
            android:layout_height="80dp">
        </Button>
    </LinearLayout>
</FrameLayout>

我有一个按钮,它完美地显示在相机上。我将要绘制的视图放在该按钮下(带有“布局(x,x,x,x)”)。他们看起来很可爱(或不出现,取决于)。

这是一些有用的代码
//在oncreate方法中
     customCamera = (CustomCameraView)this.findViewById(R.id.cameraView);

//创建视图并将其添加到布局中

public void initObjects() { listPoiMarker = new LinkedList<POIMarker>(); int i = 0; while (i < names.length && names[i] != null) { Location locTmp = new Location(LocationManager.NETWORK_PROVIDER); locTmp.setLatitude(coordonates[0][i]); locTmp.setLongitude(coordonates[1][i]); POIMarker tmp = new POIMarker(getApplicationContext()); tmp.setPoiId(id[i]); tmp.setId(i); tmp.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); tmp.setName(names[i]); tmp.setLocation(locTmp); tmp.posScreenY = 100 + (i) * 60; listPoiMarker.add(tmp); tmp.setOnTouchListener(onTouchListener); ((LinearLayout) findViewById(R.id.poiGroup)).addView(tmp); tmp.layout(50, 50, 250, 250); i++; } }

不完全是我所做的。事实上,布局功能在其他地方。但它是一样的。

这在 Android 4.1.1 中运行良好,但在 2.2 或 2.3 中不行,我寻找了大约 2 天的解决方案。我尝试了 999 件事情,没有一件奏效。这就是我来这里寻求帮助的原因。

(这里是它的一个例子:http: //drawsave.com/19Z 我不想添加图片.. 太长了

红色的是我添加的视图。应该是一个长方形。但它很可爱,在 2.2 | 2.3 ..)

感谢帮助

编辑:

我找到了修复它的方法。如何 ?我在包含视图的布局中添加了透明背景。所以它不再调整大小,它保持正确的大小。(是的,这不是很合乎逻辑,但它有效)

4

0 回答 0