を含むカスタム ビューで非常に奇妙なことが起こっていTextView
ます。大まかに言えば (以下の関連コード)、カスタム ビュー (のサブクラスFrameLayout
) がありますView
。膨張したビューには、TextView
以下で「ラベル」と呼ばれる が含まれます。また、(コードを見ない場合に備えて) 関連する可能性があるのは、カスタム ビューが子としてMapView
.
次の本当に奇妙なことが起こります。
- 何もしない: ラベルは表示されず、親は正常に見えます。興味深いことに、親ビューはラベルの幅を明確に考慮しています (
GONE
親ビューに設定されたラベルの可視性ははるかに狭いです)。デザイン モードでは、ラベルが表示されます。 - 親ビューをタッチ: ラベルが一時的に表示されてから消えます。指を長押しすると、タッチを終了するまでラベルが表示されたままになります。
this.setPressed(true)
親ビューのコンストラクターから、もちろん親ビューである を呼び出しthis
ます。Label が表示され、親ビューがタッチされるまでその状態を保ちます。その後、動作は「通常」に戻ります。
関連するコードは次のとおりです。コンテキストとして、マップにタッチすると、マップにバルーンが貼り付けられます。これには、「タップしてこの場所を選択してください」という行に沿った何かが含まれている必要があります。バルーンには他にもいくつかのビューがありますが、それらの可視性はGONE
初期設定に設定されており、それらを埋めて表示するコードは無効になっています。マップ オーバーレイは関係なく、ビューをマップに直接アタッチしMODE_MAP
て 1 つの場所に貼り付けるだけです。
カスタム ビューから、BalloonView.java. このクラスでは、レイアウト/ビュー メソッドに触れるものは他にありません。
public BalloonView(Context context) {
super(context);
if(!isInEditMode()){ // RoboGuice doesn't like edit mode
RoboGuice.getInjector(context).injectMembersWithoutViews(this);
}
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// We're *not* attaching the view with it's default layout params.
View v = inflater.inflate(R.layout.balloon_view, this, false);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
params.gravity = Gravity.NO_GRAVITY;
addView(v,params);
label = (TextView) v.findViewById(R.id.label);
addressContainer = v.findViewById(R.id.addressContainer);
address1 = (TextView)findViewById(R.id.address1);
address2 = (TextView) findViewById(R.id.address2);
// makes label visible initially
// setPressed(true);
}
// This is the constructor that we actually call, in case it matters...
public BalloonView(Context context, OnClickListener onClick) {
this(context);
setOnClickListener(onClick);
}
balloon_view.xml
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="6dip"
android:layout_marginLeft="6dip"
android:layout_marginRight="6dip"
android:layout_marginTop="6dip"
android:text="@string/map_balloon_label"
android:enabled="true"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:id="@+id/addressContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="6dip"
android:layout_marginLeft="8dip"
android:visibility="gone" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/place"
android:src="@drawable/location_place" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:orientation="vertical" >
<TextView
android:id="@+id/address1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:visibility="visible" />
<TextView
android:id="@+id/address2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
ここでBalloonView
、MapView
プライベート MapView.LayoutParams getBalloonViewLayoutParams(GeoPoint where){ return new MapView.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, where, MapView.LayoutParams.BOTTOM_CENTER); にアタッチします。}
private void showBalloon(QPGeoPoint where) {
latitude = where.getLatitude();
longitude = where.getLongitude();
BalloonView bv = getBalloonView();
if(bv.getParent() != mapView){
Ln.d("bv.getParent()!=mapView");
mapView.addView(balloonView, getBalloonViewLayoutParams(where));
}else{
Ln.d("parent was map view");
balloonView.setLayoutParams(getBalloonViewLayoutParams(where));
}
balloonView.setVisibility(View.VISIBLE);
balloonView.setLocation(where);
}
その他の(おそらく)関連するもの:
ActionBarSherlock、RoboGuice、および roboguice-sherlock プラグインを使用しています。
アプリケーションのテーマはシャーロックに設定されています。
Theme.Light.DarkActionBar
ですが、問題のアクティビティのテーマは に設定されていTheme.DeviceDefault.NoTitleBar
ます。
私は完全に困惑しており、何時間もこれを理解しようとしてきましたが、引き続きそうし、新しい手がかりを見つけたら更新を投稿します.