Andreas R.
- Forum-Beiträge: 1
05.04.2011, 19:30:10 via Website
05.04.2011 19:30:10 via Website
Hi,
ich baue eine App, die eine MapActivity anzeigt. Je nach Aktion möchte ich ein Popup mit Informationen öffnen. Das Popup soll zentriert über der Map erscheinen und nicht über die gesamte Breite der MapActivity gehen. Man soll also an den Seiten die MapActivity weiter sehen.
Ich hatte das bisher mit zwei Activities gelöst. Also die MapActivity und dann wurde eine zweite Activity (popup.xml) gestartet. Das hat wunderbar geklappt. Jetzt wollte ich das Popup aber als zusätzlichen View mit visible/invisible realisieren. Das klappt soweit auch, aber das Popup öffnet sich aber nicht zentriert, sondern immer oben links. Ich habe schon mit einigen Layouts experimentiert, aber irgendwie klappt das nicht.
Hat jemand einen heißen Tipp, warum das bei mir nicht geht?
Die Activity-Klasse (gekürzt):
Das Layout der Map-Activity (mapiew):
Das Layout des Popups (popup) (gekürzt):
Danke schonmal für Hinweise. Vielleicht bin ich auch grad betriebsblind :-)
ich baue eine App, die eine MapActivity anzeigt. Je nach Aktion möchte ich ein Popup mit Informationen öffnen. Das Popup soll zentriert über der Map erscheinen und nicht über die gesamte Breite der MapActivity gehen. Man soll also an den Seiten die MapActivity weiter sehen.
Ich hatte das bisher mit zwei Activities gelöst. Also die MapActivity und dann wurde eine zweite Activity (popup.xml) gestartet. Das hat wunderbar geklappt. Jetzt wollte ich das Popup aber als zusätzlichen View mit visible/invisible realisieren. Das klappt soweit auch, aber das Popup öffnet sich aber nicht zentriert, sondern immer oben links. Ich habe schon mit einigen Layouts experimentiert, aber irgendwie klappt das nicht.
Hat jemand einen heißen Tipp, warum das bei mir nicht geht?
Die Activity-Klasse (gekürzt):
1public class MyMapActivity extends MapActivity {
2
3 @Override
4 public void onCreate(Bundle savedInstanceState) {
5 super.onCreate(savedInstanceState);
6 setContentView(R.layout.mapview);
7
8 MapView mapView = (MapView) findViewById(R.id.mapview);
9 mapView.setBuiltInZoomControls(true);
10
11 View popupOverlayView = getLayoutInflater().inflate(R.layout.popup, null);
12 popupOverlayView.setVisibility(View.INVISIBLE);
13
14 RelativeLayout.LayoutParams layoutParams =
15 new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
16 RelativeLayout.LayoutParams.WRAP_CONTENT);
17 layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
18 addContentView(popupOverlayView, layoutParams);
19 }
20}
2
3 @Override
4 public void onCreate(Bundle savedInstanceState) {
5 super.onCreate(savedInstanceState);
6 setContentView(R.layout.mapview);
7
8 MapView mapView = (MapView) findViewById(R.id.mapview);
9 mapView.setBuiltInZoomControls(true);
10
11 View popupOverlayView = getLayoutInflater().inflate(R.layout.popup, null);
12 popupOverlayView.setVisibility(View.INVISIBLE);
13
14 RelativeLayout.LayoutParams layoutParams =
15 new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
16 RelativeLayout.LayoutParams.WRAP_CONTENT);
17 layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
18 addContentView(popupOverlayView, layoutParams);
19 }
20}
Das Layout der Map-Activity (mapiew):
1<?xml version="1.0" encoding="utf-8"?>
2<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:id="@+id/main" android:layout_width="fill_parent"
4 android:layout_gravity="center"
5 android:layout_height="fill_parent">
6 <com.google.android.maps.MapView
7 android:id="@+id/mapview"
8 android:layout_width="fill_parent"
9 android:layout_height="fill_parent"
10 android:enabled="true"
11 android:clickable="true"
12 android:apiKey="xxxx" />
13</LinearLayout>
2<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:id="@+id/main" android:layout_width="fill_parent"
4 android:layout_gravity="center"
5 android:layout_height="fill_parent">
6 <com.google.android.maps.MapView
7 android:id="@+id/mapview"
8 android:layout_width="fill_parent"
9 android:layout_height="fill_parent"
10 android:enabled="true"
11 android:clickable="true"
12 android:apiKey="xxxx" />
13</LinearLayout>
Das Layout des Popups (popup) (gekürzt):
1<?xml version="1.0" encoding="utf-8"?>
2<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:orientation="vertical" android:layout_height="wrap_content"
4 android:layout_width="wrap_content"
5 android:background="@drawable/button_bg"
6 android:layout_gravity="center"
7 android:minWidth="280dp"
8 android:minHeight="180dp"
9 android:paddingBottom="8dp">
10
11 <LinearLayout>
12 <TextView/>
13 <ImageButton/>
14 </LinearLayout>
15
16 <ImageView/>
17 <VideoView/>
18
19 <ScrollView>
20 <TextView/>
21 </ScrollView>
22</LinearLayout>
2<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:orientation="vertical" android:layout_height="wrap_content"
4 android:layout_width="wrap_content"
5 android:background="@drawable/button_bg"
6 android:layout_gravity="center"
7 android:minWidth="280dp"
8 android:minHeight="180dp"
9 android:paddingBottom="8dp">
10
11 <LinearLayout>
12 <TextView/>
13 <ImageButton/>
14 </LinearLayout>
15
16 <ImageView/>
17 <VideoView/>
18
19 <ScrollView>
20 <TextView/>
21 </ScrollView>
22</LinearLayout>
Danke schonmal für Hinweise. Vielleicht bin ich auch grad betriebsblind :-)
— geändert am 05.04.2011, 19:30:48
Empfohlener redaktioneller Inhalt
Mit Deiner Zustimmung wird hier ein externer Inhalt geladen.
Mit Klick auf den oben stehenden Button erklärst Du Dich damit einverstanden, dass Dir externe Inhalte angezeigt werden dürfen. Dabei können personenbezogene Daten an Drittanbieter übermittelt werden. Mehr Infos dazu findest Du in unserer Datenschutzerklärung.