xml und Context

  • Antworten:1
  • Bentwortet
Dominic Warzok
  • Forum-Beiträge: 19

13.01.2012, 10:41:24 via Website

Hallo zusammen,

ich bin grade dabei ein Coverflow in meine App zu integrieren. Solange ich auch nur das Coverflow im Code erzeuge klappt das auch alles wunder bar aber wenn ich es in der xml erzeugen will geht es nicht mehr.

Soweit ich das bisher überblicken kann liegt das Problem im Context. Vielleicht könnt ihr mir ja helfen.

Hier meine xml:

1<?xml version="1.0" encoding="utf-8"?>
2<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:layout_width="fill_parent"
4 android:layout_height="fill_parent"
5 android:orientation="vertical"
6 android:id="@+id/layout" >
7
8 <TextView
9 android:layout_width="fill_parent"
10 android:layout_height="wrap_content"
11 android:text="@string/hello" />
12
13 <de.foo.CoverFlow android:layout_width="fill_parent"
14 android:layout_height="fill_parent"
15 android:id="@+id/gallery">
16
17
18
19 </de.foo.CoverFlow>
20
21</LinearLayout>

Und hier mal der Anfang von CoverFlow.java (also die Konstruktoren):

1public class CoverFlow extends Gallery
2{
3 private static Context con;
4 /**
5 * Graphics Camera used for transforming the matrix of ImageViews
6 */
7 private Camera mCamera = new Camera();
8
9 /**
10 * The maximum angle the Child ImageView will be rotated by
11 */
12 private int mMaxRotationAngle = 60;
13
14 /**
15 * The maximum zoom on the centre Child
16 */
17 private int mMaxZoom = -200;
18
19 /**
20 * The Centre of the Coverflow
21 */
22 private int mCoveflowCenter;
23
24 public CoverFlow(Context context)
25 {
26 super(context);
27 this.setStaticTransformationsEnabled(true);
28 }
29
30 public CoverFlow(Context context, AttributeSet attrs)
31 {
32 super(context, attrs);
33 this.setStaticTransformationsEnabled(true);
34 }
35
36 public CoverFlow(Context context, AttributeSet attrs, int defStyle)
37 {
38 super(context, attrs, defStyle);
39 this.setStaticTransformationsEnabled(true);
40 }
41...

Und hier mein Versuch das ganze in der ActivityKlasse aufzurufen:
Der Image Adapter ist eine InnereKlasse der Activity.
1public class FooActivity extends Activity {
2 /** Called when the activity is first created. */
3 @Override
4 public void onCreate(Bundle savedInstanceState) {
5 super.onCreate(savedInstanceState);
6
7 setContentView(R.layout.main);
8 CoverFlow covFlow = (CoverFlow) findViewById(R.id.gallery);
9 covFlow.setBackgroundColor(Color.CYAN);
10
11 covFlow.setAdapter(new ImageAdapter(this));
12 }

Vielen Dank schonmal für eure Mühen

Lg
Dominic

Antworten
Dominic Warzok
  • Forum-Beiträge: 19

13.01.2012, 13:42:13 via Website

Hab den Fehler selber gefunden und lag mal wieder an einer ganz anderen Stelle :(

Antworten