私は実際に、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 .. )
手伝ってくれてありがとう
編集:
私はそれを修正する方法を見つけました。どのように ?ビューを含むレイアウトに透明な背景を追加しました。そのため、サイズが変更されなくなり、適切なサイズが維持されます。(ええ、それは本当に論理的ではありませんが、うまくいきます)