custom imageview in larger layout - android

Having a bit of trouble here. I've created a custom ImageView by subclassing ImageView and I'm able to get it to display if I simply instantiate my view and set the entire contentView of my activity to my imageview via setContentView(myCustomImageView)
But what if I want to just use my custom imageview as part of a larger layout? E.g., I want a button, a textview, etc and then my ImageView somewhere in there...
I tried doing something like programatically creating a linearlayout and then instantiating my special imageview and adding it via mLinearLayout.addView(myCustomImageView) but it crashes when I do this.
Am I missing something basic here?
EDIT: apparently you just use the full namespace of your custom view in the XML.

Why don't you put your layout in the XML?
You can add you custom View like this:
<view
class="com.your_package.myCustomImageView"
id="#+id/customView"
/>
You can find more useful resources on the Android SDK documentation site
Edit: Yes, you must use the entire namespace for your self defined views. For standard views you can omit com.android.widget because the SDK knows where to find them, but for your own stuff he doesn't.

Related

how to design dynamic ui in android like the image below

i am trying to design dynamic ui layout in android to present the date like the image below. i am **facing the challenges in the creating an view as clustered in the below mail **
i tried using list view!
but the each appeares in diffrent line, it dose not lookes like the image as below! is that possible to design like this. if so how to do that?
Try to create a few custom views, e.g. this circles with dates, this labels on the left and rights with xml layouts. Next, create parent view with some container layout, e.g. FrameLayout. In this parent view override it's onDraw() method, and there manually create and add every layout. It is simple, but might be not efficent, when there are many of views

Place view elements in circular manner using custom relative layout in Android

In android there are different type of Layouts LinearLayout will place the items Linearly(Horizontal/Vertical). Where RelativeLayout can do better and can place items relative to each other items.
By Overiding the RelaiveLayout I want to create a Layout which draw elements in circular manner (as shown in picture). I am able to do this using code snippet here http://developer.samsung.com/android/samples-4
But it is creating the whole layout from java code only, so if i need to make some complex layouts which have this circle as an element in the Layout, It will make me crazy becuase I have to write a lot of code.
I want to do it in a simpler way, so that I can use the same concept in XMLs layouts.
Can anyone who experts in Making custom layouts suggest me how can I achieve the same. I want something like, I have a layout file
And from java code i will get that CircleLayout using id and Set into an Object of CircleLayout class. Now there should be some functions written in CircleLayout class using them I can do the modification in Layout like
CircleLayout circle= (CircleLayout)findviewById(R.id.circle);
circle.setRadiusOfLargestRing(20);
circle.setNumberOfRings(6);
//Define any type of view form java
View v1 =new View(Context);
circle.setCenteralView(v1);
View v2 =new View(Context);
circle.addElementOnrings(ringNumber, v2)
..so on
I want maximum three rings, I have no problem if the rings formed from drawable resounce(like three rings already placed in drawable folder).
and then we can set listeners to each view inserted in to the ring.
My layout should be smart enough to place the views in the in ring in a way shown in picture .
I will be glad If someone can help me to develop a library so others also can take benefits of the same.
I am ready to write whole code if someone can guide me.

How to do this custom label on Android?

How the ways that I can make this custom Label?
Is it a TextView with a background image?
You wont be needing a Custom View to create this.
Use a TextView with a background image and a Right Image property. Use RelativeLayout to overlap it over the coffee image.
In case you have to use it in more than one place extend a frameLayout to create a custom component.
It could be just a Imageview above another ImageView (coffee), which is above the TextView below.
You can look at Android layout and UI.
Or, it is just a mobile version of a web page, then you can look at html to find out how to do it.

Graphical Layout shows first view of ViewFlipper, how to see others?

I am using Eclipse and a ViewFlipper. In Graphical Layout, I want to see the second, third, and forth layouts of my views - right now, I can only see the first view. Any suggestions?
If I'm understanding you correctly, you want to see each view in the 'Graphical layout' tool? The way I do this, is instead of having all the layout work done in one xml (where your viewflipper is) I make each view a new layout xml. And then have each view (xml file) included into the view flipper by using this....
<include
layout="#layout/layout_media"
android:id="#+id/flipper_media" />
Hope this helps.
just put each layout in relative layout or linear what ever you are working with then with each layout you will work with the first one in the order and etc.. then at the end put each layout in the order you want later
I had to subclass the ViewSwitcher class to display an indeterminate ProgressBar until data is ready to display in the second view. I used isInEditMode() to determine whether I was actually running the app or just previewing in AS.
You should be able to add a custom attribute to choose which child to display. This might look a bit overkill, but if you happen to already have to subclass your ViewSwitcher or ViewFlipper, i think it is not a big deal.
I will try to put an example later.

how to create a buttonbar with a sliding control in android?

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.

Categories

Resources