Questions tagged [custom-view]

It is possible to create custom views by:

  • Compound views - combining views with a default wiring

  • Custom views - creating your own views

    a) by extending an existing view, e.g. Button, TextView, EditText, ListView, CheckBox, RadioButton, Gallery, Spinner, AutoCompleteTextView, ImageSwitcher, and TextSwitcher.

    b) by extending the View class

Creating custom views

By extending the View class or one of its subclasses you can create your custom view.

Creating your own View subclasses gives you precise control over the appearance and function of a screen element.

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. If the view should be re-drawn you call the invalidate() method which triggers a call to the onDraw() method of this view.

If you define own views, ensure you review the ViewConfiguration class, as it contains several constants for defining views.

To draw your Views you typically use the 2D Canvas API.

Useful links:

644 questions
10
votes
1 answer

Pass parameter from storyboard to custom UIView iOS

I have created a custom UIView and I would like to initialize it with custom parameters from the UIStoryboard. Basically I have added a UIView in the UIStoryboard and I have changed the class to my custom UIView. In my custom UIView class I'm using…
rdiaz82
  • 996
  • 12
  • 31
9
votes
3 answers

Android ProgressDialog with setContentView

I've read a hell of a lot about this, and can't see anyone who's done or tried it before. So I've got an object that extends ImageView, then within this I call a progress dialog and set the progress dialogs's content to the imageview (i.e.…
Blundell
  • 75,855
  • 30
  • 208
  • 233
9
votes
1 answer

How to getGravity() in custom view?

Can't get gravity attribute (android:gravity) from my CustomView. XML My Custom View; class MyCustomView extends LinearLayout{ ... @Override protected void onMeasure(int widthMeasureSpec, int…
Ye Min Htut
  • 2,904
  • 15
  • 28
9
votes
2 answers

Beautiful Stroked Text in Android

I know how to stroke text using custom views(EditText or TextView) but I couldn't able to achieve something beautiful like this one, which is done using Photoshop. And yes, it has outer shadow too. What I have done so far is adjusting stroke width…
Swan
  • 886
  • 1
  • 9
  • 23
9
votes
1 answer

What method of UIView gets called when instantiated from a NIB?

I have a simple custom view that is connected via outlet to a NIB. For this particular view, there are actions that I would like to perform on the view when it is initialized, no matter what NIB it is on. Trouble is, neither the (id)init or the…
please delete me
9
votes
1 answer

load custom view in MBProgressHUD

Is it possible to load a custom view in MBProgressHUD overlay, there is a custom view option with the MBProgressHUD class, but can i assign a XIB view etc with customView??
Faisal Ameer
  • 416
  • 5
  • 13
8
votes
2 answers

Custom seekbar getting its edges cut

Possible Duplicate: Android SeekBar thumb gets clipped/cut off I was doing a custom seekbar, following this tutorial: http://www.mokasocial.com/2011/02/create-a-custom-styled-ui-slider-seekbar-in-android/ But when I put the seek thumb either at…
Sergio
  • 640
  • 6
  • 23
8
votes
3 answers

Styling Custom Views

I have a few custom views in my Android project and I've added the relevant details to the attrs.xml file. And now I can implement my objects through XML. This works fine. How do I style these elements? When I try to use my custom attributes in the…
Kurru
  • 14,180
  • 18
  • 64
  • 84
8
votes
2 answers

How to unit test custom view with attribute

I'm having trouble to create a unit test for my custom view. I try to add an attribute and test it if my custom view class get it right. Here's what my test looks like: @RunWith(AndroidJUnit4.class) @SmallTest public class…
Tomaz Wang
  • 316
  • 4
  • 11
7
votes
1 answer

How to set size of custom surfaceview

Please let me know if I'm going about this totally the wrong way, but if I explain the problem I hope someone can help me with it, or point me in the right direction. I need a custom view which can have movement, I wish to put this view on part of…
ThePerson
  • 3,048
  • 8
  • 43
  • 69
7
votes
2 answers

Android: How to dynamically add a "Custom View" into a linear layout

I am a newer on building up Android application. I want to add a new "custom view", which is composed of buttons and imageView, when i click the button in the MainActivity. I have followed some of the website list below to build a custom…
Anthony
  • 123
  • 1
  • 1
  • 7
7
votes
1 answer

Android: Set match_parent in custom view programmatically

I implemented a custom view where I can paint. I want to set it to MATCH_PARENT, so that it fills the screen independent of the screen orientation. When I change orientation to landscape it fills just 50% of width. I changed onMeasure() but there…
Kewitschka
  • 1,445
  • 1
  • 21
  • 35
7
votes
2 answers

how to access custom attribute with multiple formats?

I read in another answer that in android you can declare attributes for your custom view that have multiple formats like this: how can I access these attributes in my class? Should I just assume it…
Grisu47
  • 530
  • 5
  • 16
7
votes
1 answer

Android How to get talkBack to read text when RelativeLayout is displayed

I have an activity which adds a custom view to the entire activity's view using the following code activity.getWindow().getDecorView()).addView(newView) in order to have a screen of coach marks/usertips displayed. My custom view extends from…
se22as
  • 2,282
  • 5
  • 32
  • 54
7
votes
2 answers

Null pointer exception with custom view in layout xml

Here's the custom view code which gives me a null pointer exception in the layout tab of the XML which uses this view: public class BoardView extends View { // Drawables for the board boxes, the playable zone public Drawable[][] block = new…
Jan
  • 3,393
  • 4
  • 21
  • 47
1 2
3
42 43