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
0
votes
2 answers

Which component can I use in Android Studio for the purpose of creating a touchpad?

I've been searching for a View/Component in Android Studio that I could use for creating a touchpad. I need the ability to track mouse movements, so that I use that information on the server side to handle it and emulate mouse movements. What would…
Maksim I. Kuzmin
  • 1,170
  • 7
  • 16
0
votes
2 answers

Android customview ondraw variable

I have a customview where i display two rectangles. i want to set the height by a variable i sent from the mainactivity. my customview class is the following. package com.example.customview; import android.content.Context; import…
Ingolf Krauss
  • 161
  • 1
  • 2
  • 23
0
votes
0 answers

Adding a view inside a custom view

I am trying to add a progressbar(circular spinner) inside a RelativeLayout. The relativeLayout is visible, however the progressbar doesn't show up. Following is the code I am using but it doesn't seem to work. public class MyCustomView extends…
user2498079
  • 2,872
  • 8
  • 32
  • 60
0
votes
0 answers

Diplaying bitmap in custom view with scale type center inside

I have customview for displaying two bitmaps but the problem is it is scaling to center crop but I don't want to crop bitmap instead I want to display full bitmap in canvas. protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { …
0
votes
0 answers

Force close when calling Picture.draw(canvas) in onDraw(Canvas canvas) android custom View

I'm trying to draw an android Picture with onDraw() method in a custom View: MapView extends View implements View.OnTouchListener { Picture pictureBuilding; Picture pictureMarkers; Canvas frameBuildingCanvas; Canvas…
Nagash
  • 1
  • 2
0
votes
1 answer

Android custom view - setting it to take up max space available but no more

I have a custom View class in my app that I'm using in xml layouts. Wherever I'm using this view in my xml, I don't want it to stretch it's container, but I want it to fill out whatever space is available. Here's an example to make it a little…
Rich
  • 36,270
  • 31
  • 115
  • 154
0
votes
0 answers

Add picker view to a UIView

My app is related to the custom views. In single view controller, there are 14 buttons. When each button is clicked, custom view containing picker view should appear along with ok and cancel buttons and transparent background. I have written code…
iosdeveloper
  • 99
  • 3
  • 13
0
votes
1 answer

How get the size or the image from DrawableLeft in EditText

I am doing a floating hint to editText, but to make it perfect I need to know how is the size from image used in drawable left and I would like to know if is possible to get the attribute set from the original editText.
0
votes
0 answers

Should I Create Custom View Using Subclass or Interface Builder?

I am trying to create a custom view with a white border around it to act as a container for several subviews. I can create this by adding a UIView object in Interface Builder, and setting the border in User Defined Runtime Attributes, but this…
0
votes
1 answer

Android custom-view - java.lang.RuntimeException android.view.InflateException

I have a problem creating a widget. I'm usign Android Studio v1.0. For starting I choosed to follow those lineguides: http://developer.android.com/training/custom-views/create-view.html And this is what I've done: activity_home.xml:
ste.cape
  • 45
  • 11
0
votes
3 answers

Using Custom View in IB

I have a Custom View I created that should appear in several View Controllers in the App. So... I've created a subview of UIView with xib, h and m files for it (and set the View in the xib file with the Class), added my UIs to the view xib file and…
Ohad Regev
  • 5,641
  • 12
  • 60
  • 84
0
votes
3 answers

How to create a repeatable view in iOS and XCode

I am somewhat new to iOS, but am experienced in Android. I have an app I am working on and it needs to populate a page with your "history" of past people you've interacted with, and it shows their picture, name, rating, and some other information.…
Jake Weso
  • 555
  • 1
  • 6
  • 14
0
votes
0 answers

Android Custom View Animation

Hy, I'm trying to do an animation of a circle drawn on canvas. I can do that pretty easily with ObjectAnimator, however I'd like to start the animation when the view finishes loading or finishes drawing. If I start the animation in init(), the…
box
  • 4,450
  • 2
  • 38
  • 38
0
votes
1 answer

UIView in a ViewController using swift

I have a custom view (.xib and .swift) and I want to use it in different ViewControllers and as a custom cellview. the thing is I don't know how to do this :P. can anyone please help me out on how to accomplish this? my custom view is RestaurantVie,…
Opticon
  • 3
  • 7
0
votes
2 answers

How to create custom seekbar and do optimization?

I try create a custom seekbar like this : https://i.stack.imgur.com/8B0Q8.png But i encountered problem this problems : https://i.stack.imgur.com/rcQG7.png I use this project for dynamically change text :…