einfache benutzerdefinierte view-Klasse erweitert
ich möchte erstellen Sie eine benutzerdefinierte view-Klasse. Aber ich bekomme eine Fehlermeldung durch ausführen der app.
hier meine Klasse:
package test.start;
import android.util.AttributeSet;
import android.view.*;
import android.graphics.*;
import android.content.Context;
public class control extends View{
private Paint paint;
public control(Context context, AttributeSet attrs, int defStyle){
super(context, attrs, defStyle);
init();
}
public void init(){
paint = new Paint();
paint.setTextSize(12);
paint.setColor(0xFF668800);
paint.setStyle(Paint.Style.FILL);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawText("TEEEST", 100, 100, paint);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
this.setMeasuredDimension(150,200);
}
}
und die main.XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:orientation="vertical">
<TextView android:id="@+id/textView1" android:text="@string/text" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<TableLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/tableLayout1">
<Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:background="@drawable/custom_button" android:layout_weight="1"></Button>
<Button android:layout_width="wrap_content" android:id="@+id/button1" android:layout_height="40dip" android:text="@string/button" android:layout_weight="1"></Button>
<test.control
android:id="@+id/control"
android:layout_width="match_parent"
android:layout_height="match_parent"> </test.control>
</TableLayout>
</LinearLayout>
Fehlermeldung:
Unable to start activity
ComponentInfo{de.mich.starten/testen.start.StartActivitiy}:
android.Blick.InflateException: Binäre
XML-Datei Zeile #10: Error inflating
Klasse test.start.Kontrolle
Blockquote
Aber ich kann die Ansicht des Steuerelements in das grafische layout.
InformationsquelleAutor passsy | 2011-03-21
Du musst angemeldet sein, um einen Kommentar abzugeben.
Versuchen, eine weitere version des Konstruktors:
InformationsquelleAutor alex.zherdev
Sollten Sie erklären, es in der XML-Datei in der folgenden Art und Weise:
ich habe. gibt es irgendein Beispiel-Projekt mit einer vordefinierten Klasse erweitert?
Hi Passy,haben Sie gefunden, einen Beispiel-Projekt, das u gesucht ?... Bitte teilen Sie uns mit, falls vorhanden. Dank
InformationsquelleAutor MByD