In my application I need to have something like image below. I have experience of creating custom components and I know how to do it. However, I have no idea how to create this kind of component. Do I need to do something like when we are designing custom rating bar?
Anyway, their so many way you can achieve this.
One way i am seeing using radio group and radio button, vertical lines and text view you can easily achieve this. Put everything inside a layout of your choice and then just inflate the layout where ever you need. After that you just need to set the radio button like this radio1.setChecked(true).This is a simple solution but may not a be a optimal one.
Alternatively you can create a custom view by extending view class or any of its subclass, whatever you feel suitable for your work then override its onDraw method do the entire thing manually.
Related
I am trying to create a program with some kind of list which is dropped down when you are clicking in the desired category and reveal some items in there.
I am new to layouts and XML editing, so I would love to have a tip where to start with.
I tried RelativeLayout but then I am stacked.
I don't want you to write the code for me, just some suggestions for what Layout is better to use and I will do my research for that. Thanks.
Use ExpandableListView class, with a custom view for the children :-)
I need to change the look and feel of the Spinner View, so the little triangle in the lower right part is a bit bigger, and with a circular shape in his "back".
I've been looking but all the tutorials refer to the custom adapter part of customizing a Spinner.
Anybody knows some tutorial to look at to change the appearance of a View?
Thank you.
There are three ways to build a custom view:
1- By extending the view
2- Compound many views
3- Create a totally new one
Here an example: http://developer.android.com/training/custom-views/create-view.html
I could use some help with merging multiple views into one, like Pinterest has at
I know how to make a reusable custom view, been searching around custom components, compound controls, checked sdk samples and threads like Custom view made of multiple views , but it was never the proper way. I want it to also show 1 view (where i can set the image/texts dynamically) at the hierarchy viewer instead of 5+ child subviews, as that way increases performance aswell. I checked the github acc of Pinterest too without success :)
Can I somehow achieve it, or Im way too off? Thanks!
Try creating a separate layout.xml file containing all of the views you want to have in your custom view. Then in java all you would have to do is make reference to each of those custom views and fill them with your data.
The footprints and clock app on a HTC sense phones use a slider control on the bottom buttonbar (see this movie for an example: https://docs.google.com/leaf?id=0B9hmEy_z2CRzOTJmYTVlNDktYjkwMS00YTM5LTk3ODQtYmIzODU4Yzk1YjA0&hl=en&authkey=CMWwwegG).
From the hierarchy viewer I can see that they use a custom control for this. I'm looking for a way to achieve the same effect. I want a buttonbar on the bottom of my app with a movable selector which I can drag from left to right and back, thereby selecting the different tabs.
Can anyone give some tips on how I might achieve this? Which layout controls could I use for this purpose? I know how to create the tabs and the button bar, but I'm a bit puzzled on the sliding selector.
Thanks and kind regards,
Ivo
To create a view, you have two main options.
One is to define it in XML, in a layout file your Activity will use.
<LinearLayout ... > <!-- or any other layout, see layout documentation in the SDK -->
<ImageView ... <!-- or another view as fits your needs -->
android:id="#+id/myview"
android:src="#drawable/myimage" ... />
</LinearLayout>
You can then reference your view in your code, after you called setContentView, with findViewById(R.id.myview). (of course, if you said, say, "#+foo/bar" in the XML file, you'd use R.foo.bar).
The other way is to create it dynamically and attach it to the view hierarchy.
ImageView v = new ImageView();
v.setImageResource(R.drawable.myimage);
... // initialize your view here
parent.addChild(v);
...Or so.
To get events, you have several options again.
One of them is to subclass View (or ImageView for that matter) and implement onTouchEvent. You'd need to adapt the code above to create an instance of your new class instead of an ImageView (obvious in Java code, for XML you'd write as tag name and make sure you implement the constructor that takes (Context, AttributeSet) to call its superclass' constructor).
Or, you could write a TouchDelegate and use setTouchDelegate on your ImageView, which is probably simpler in your case.
Another approach would be to create a GestureDetector and to match touches to your view using its hitTest method. For the task you are describing it's overkill, but it might come in handy when your application becomes more complicated.
I would extend the TabWidget class to do my own rendering. You'd have the benefits of hot-swappability with other tab systems and uniform interface, while still being able to draw your tab bar the way you want.
You'd start your animation in setCurrentTab.
I have numerous activites in my Android app., and most should contain the same, relatively complex set of UI widgets on the screen's top area (lets say that its a kind of toolbar that you can find on most screens).
Right now, every screen's layout contains the markup for this toolbar, along with its logic inside every Activity's source, so it's damn redundant. Could you recommend a more efficient / less redunant way to do this?
I would take advantage of the <include> tag in the layout's xml. This will let you reuse that toolbar very easily and effectively. As for the code I would subclass Activity and place the logic in there, then each of you activities can subclass your custom Activity class.
There are 3 very useful articles on the dev site about this topic. Here is the first one link
I would create a custom View object (subclass View) and then include it in all of your layout xml. You can actually pass parameters, etc. just like built in views. Then define XML for that view that will always be used when that view is drawn on the screen. Also, this allows you to change the view and have that change populated across all of your Activities without having to manually modify all of the code.