Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use own view in layout?

I created a class like this

public final class MyView extends View {

    public MyView(Context context, AttributeSet attrs) {
        super(context, attrs);
        [...]
    }
        [...]
}

and then I want to use it within my layout.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="fill_parent"
             android:layout_height="fill_parent">

  <com.hitziger.barcode.MyView
      android:id="@+id/my_view"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"/>

</FrameLayout>

But Eclipse tells me in the error log

AndroidManifest: Ignoring unknown 'com.hitziger.barcode.MyView' XML element

How can I make MyView accessable within a layout? Do I have to publish this class elsewhere?

like image 899
hitzi Avatar asked Apr 01 '11 13:04

hitzi


People also ask

How do I use custom view?

Creating custom views. By extending the View class or one of its subclasses you can create your custom view. For drawing view use the onDraw() method. In this method you receive a Canvas object which allows you to perform drawing operations on it, e.g. draw lines, circle, text or bitmaps.

How do I use custom views in Excel?

Create a custom viewGo to View > Workbook Views > Custom Views > Add. In the Name box, type a name for the view. Tip: To make a view easier to identify, you can include the name of the active worksheet in the name of a view. Under Include in view, select the check boxes of the settings that you want to include.

What is customized view?

Custom Views is just a way to make an android developer a painter. When you need to create some custom and reuse the views when it is not provided by the Android Ecosystem. Custom Views can be used as widgets like TextView, EditText etc.

What is custom layout in Android?

Android provides a series of different layouts to suit your apps needs. One of the quickest and easiest ways to display information to users is via the ListView component. This component creates a simple scrollable region that can display unique sets of information.


1 Answers

You should write it like:

<view class="com.hitziger.barcode.MyView"...
like image 187
MByD Avatar answered Oct 02 '22 11:10

MByD