How to create View Stub? - android

I am new to android.. I have a slider in my xml. For the particular value of the slider I want an Image to appear and later disappear.. I heard that View Stub can do the trick.. But not exactly getting the solution.. Can any one please help me..
Thanks,
Keerthiraj

ViewStub is used when you have a "heavy" view which is hidden but may be shown later. ViewStub is a light-weight view which inflates the real view at run-time when it's made visible.
So ViewStub doesn't solve your problem. I thinks the best solution for you is to set ImageView's visibility:
imageView1.setVisibility(View.GONE);
imageView2.setVisibility(View.VISIBLE);

Related

How does reply layout appears in android chat app?

I'm creating an android chat. In Telegram Android app, when I touch on reply, a layout appears and I want to how to do the same thing. I tried to the same with an extra constraint layout and make it visible or invisible when necessary.
What is the best way to do this?
Please view types in your adapter. Please see the example https://medium.com/#droidbyme/android-recyclerview-with-multiple-view-type-multiple-view-holder-af798458763b
I achived this with add view. By adding constraint layout into Linearlayout. Anyone with better and best practice, please share your answer.
LinearLayout item = findViewById(R.id.reply_layout);
View child = getLayoutInflater().inflate(R.layout.reply_layout, null);
item.addView(child);

How to put a layout on top of layout.setZOrderOnTop()

I've a SurfaceView for a book for pagecurl.
I wanted it to be transparent for some reasons and I've used
myView.setZOrderOnTop()
to achieve it. Till now, everything is working perfectly.
Now I need to put some views (suppose an ImageView) on top of this surfaceview (book). When I do so, the imageview is hidden behind the book. The part of it that is outside book bounds, is visible as expected. I've added the imageview in last of XML but don't find a way to change the z order of imageview so that it becomes visible on book.
Please suggest me a way to achieve this.
NOTE: I can't remove setZOrderOnTop() unless there is any other solution to make my surface view transparent.
I don't know your code but hope it will help you:
view1.setZOrderOnTop(false);
view2.setZOrderOnTop(true);
view2.setZOrderMediaOverlay(true);
In my case:
Try to play with this,
see reference of setZOrderMediaOverlay here
I have a VideoView with a View over it in xml.
For me, the solution was
videoView.setZOrderOnTop(true)
videoView.setZOrderMediaOverlay(true)

Android - how to draw in a multiple view layout

i have to draw a ball inside a view (or anything else that is good for this task).
I have followed some tutorial about the matter, but every tutorial that i have found
uses only one view (that is shown on the screen without the use of a layout).
But in my Activity i use a layout, that is composed by many views, and i want to draw
only on one of them.
here a little mockup!
Anybody knows a way to do it?
Is the view the wrong container to do it?
Thanks is advance!
Bye
...
You should extend a view that inherits from ViewGroup. this kind of view lets you handle a view that contains other views. with that, you can control the drawing, measures and layout of each of it's children separately
Your mockup can be made with a LinearLayout, which will contain some TextView's and you own View (the one which is containing the ball).
I'm surprised by this question, because there are many examples over the net explaining how to build a layout containing multiple views.

How to make a view fit a layout?

I have a main layout in which i'm adding dynamic view inflated, i do this add in scale with the main layout but in some cases the view exceeds the mainl layout height.How can i tell them to stick to the layout height and not cross over?
Thank you
Please provide the code, so that I can help you by analyzing it. Try using proper LayoutParams. why do you want to add View dynamically. If you can make it in XML, make 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.

Categories

Resources