I would like to show progress bar (in form of rotating circle or something similar) when loading image from remote location.
I don't want standard ProgressBar that gets shown in the middle of the screen. I would like to have it in the middle of the imageView (or Layout that holds ImageView). Is there easy way to do this? For example, do I have option to attach progressBar to some View?
I was reading about FrameAnimation. I think I will do that, but first I want to make sure that I am not reinventing the wheel.
Thanks.
Do you mean like a spinner ?
Yes you can do that:
heres a sample code:
<!--Grey Spinner-->
<ProgressBar
android:id="#android:id/progress"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<!--Black Spinner-->
<ProgressBar
android:id="#android:id/progress"
style="?android:attr/progressBarStyleSmallInverse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
Here are some other style attributes you can use, just replace above style attributes with one of these, e.g. style=?android:attr/<one of the attribute from below list>
progressBarStyleSmallTitle
progressBarStyleLarge
progressBarStyleLargeInverse
progressBarStyleHorizontal
progressBarStyleSmallTitle
You must also note that if you are downloading image from internet do not use UIThread. And you can also add progress bar in the title bar.
Add spinner to title bar with following code(call request.. in onCreate()):
requestWindowFeature(Window.FEATURE_PROGRESS);
//calling setContentView() after requesting
setContentView(R.layout.main);
setProgressBarVisibility(true);
//call setProgressBarVisibility(false); to turn it off
Hope this helps.
Cheers!
you can attach a ProgressBar into ImageView layout holder,
RelativeLayout
-> ImageView
->ProgressBar
then you can set layout align params to the progress bar to show it where you want.
you can do this in a xml layout and inflating later programatically, so, when you start/stop the image download process you can set the ProgressBar visibility on/off
Related
i'm trying to hide a linear layout at screen and it is some of the screen and if i use
android:visibility="invisible"
it take a space from the screen and i won't to be invisible and other element must show in the right sequence
is there is a method in xml to do that or in Java code ?
Set android:visibility="gone" or programatically setVisibility(View.GONE)
Don't know if I undestand what you're trying to do, but invisible will hide the element, but the element will still use up it's space. Use gone to completely remove the element.
You can change the visibility of the element either by XML or pro-grammatically
Via Program
TextView text =(TextView)findViewById(R.id.textView);
text.setVisibility(View.GONE); //Completely hide from container
or
text.setVisibility(View.INVISIBLE); //it occupy space and view will hide
Via xml
andoid:visibility ="gone"
-------->
How do I go about implementing a button bar with buttons of different shapes and heights? As an example (please excuse my poor drawing skills for this quick mockup):
The example bar has 3 buttons, with the middle button (3) a different shape and height than the other 2 buttons (1,2). The button bar will be a view that is included and merged into other views so as to seem to float on top of the parent view.
I was thinking of implementing buttons 1 and 2 into a layout, and then button 3 as another layout that I then merge with the first two button's layout.
like my previous comrades said, you need some kind of layout or container that can have a background (if you wish for button #3 to hoover above it) then use relative layout for mixing the two the disadvantage of this other than complexity is that youcannot relate to the other two buttons since they reside in a different layout.
More elegant solution may be to have a special background drawable that can:
have a method setCurrentHeight() that will specify the height the actual viewable section should have the rest will be filled with transparent color.
override it's own draw so just before it's drawing it will have a callback called, call back you can register yourself to.
then you can register the callback in your activity to take the current position of the #3 button and set the height accordingly, this way you are still with one layout with special drawable as background.
A customized LevelDrawable might do the trick.
I would layout this bar as follows:
A RelativeLayout as a container for the rest, with height set to wrap_content and alignparentbottom = true
An ImageView for the bar
2 Buttons with a transparent background (Button 1 and 2)
Button 3 is a custom Button with a custom Image of a trapezoid as background
So you will have a Layout similar to this:
<RelativeLayout
...>
<ImageView
.../>
<Button
... Button 1 />
<Button
... Button 2 />
<Button
... Button 3 />
</RelativeLayout>
I don't exactly know that this will work, and I can't test it, but you might give something like this a try; I believe it can all be done elegantly through XML.
Have a RelativeLayout (id:mainLayout) that will contain all of your views, wrap_content for both dimensions.
Have a blank View as your first child that will serve as your background bar
Set the View's background color/image to what you want; layout_width to fill_parent; layout_height to wrap_content; layout_alignTop="#id/leftButton"; layout_alignBottom="#id/leftButton".
Add an ImageButton for your center button (id:bigButton), wrap_content for both dimensions; layout_centerInParent="true".
Add an ImageButton for your left button (id:leftButton), wrap_content for both dimensions; layout_toLeftOf="#id/bigButton"; layout_centerInParent="true".
Add an ImageButton for your right button (id:rightButton), wrap_content for both dimensions; layout_toRightOf="#id/bigButton"; layout_centerInParent="true".
In my head, I believe this works, but I could be off. Regardless, something to think about, and I hope it helps you find a solution. :)
Better you can tablelayout with different button styles or relative layout for button "3"
I have a hidden image button in one of my xmls layouts, with a background set to a drawable image. I set the visibility to invisible, as I only want the image to display every once in a while. The problem is, even if the drawable isn't shown, the image button still takes us space - Is there a way to hide the background image, and make it's dimensions 0 until I call on it to be shown in my main class?
Thanks!
Edit: So in my xml, how would I write that?
<ImageButton android:id="#+id/myimage" android:visibility="invisible"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:background="#drawable/my_image"></ImageButton>
I want to have the image always gone, unless a certain condition occurs, I then want the image to be visible under that one condition. So in my xml I would need to be set to GONE, but in my conditional statement so I say something like:
myimage.setVisibility(SHOW);?
Try setting the visibility to GONE
Don't set the width/height to zero, that's ugly. The view will always take up the space, unless you change the visibility setting. This is the code you want:
myImageButton.setVisibility(View.GONE);
View.GONE - invisible, takes up no space
View.INVISIBLE - invisible, but still takes up space
View.VISIBLE - use this to bring it back
All views, including ImageButton, inherit from android.view.View, so they all have a visibility attribute that can be set. Instead of setting the visibility of the drawable resource, set it on the ImageButton.
Set Visibility property of Imageview like this in java
imgView.setVisibility(View.VISIBLE);
imgView.setVisibility(View.INVISIBLE);
imgView.setVisibility(View.GONE);
Or like this in XML
android:visibility="visible"
android:visibility="gone"
android:visibility="invisible"
Result for each will be like this
Please refer the image given in the url
http://docs.google.com/Doc?docid=0AQhgDtGvE2HgZGZ6cmtua185M2RneG5nYmNm&hl=en
My query is, How can I display the messages corresponding to the rounded buttons and the table row , when I click on the rounded button with question mark.
I know, I have to use listener for the ? button , but what should I do in listener exactly, such that when I click, it shows those alerts(images) and when I click again, it disappears.
For this UI, I have used Relative layout as was suggested here -- Aligning components at desired positions -- and it worked perfect for me.
So, do I need to change my base layout altogether for accomplishing this?
You can use a FrameLayout as the base for your ui layout and then add an ImageView overlay. For example:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/MainFrame"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- Put your normal layout stuff here -->
</FrameLayout>
Then in your code you can create the ImageView and add it to the MainFrame and it will overlay your UI, like this:
FrameLayout mainFrame = (FrameLayout)findViewById(R.id.MainFrame);
ImageView overlay = new ImageView(this);
overlay.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.overlay));
mainFrame.addView(overlay);
Then later you can call:
mainFrame.removeView(overlay);
to have it go away.
I would like to create a button with circular or rectangular background, text and an image below or above the text.
Here is the CustomButton Layout where I added the objects (background and text - ImageView is missing):
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:orientation="horizontal" android:layout_width="wrap_content" android:layout_gravity="center_vertical|center_horizontal">
I would like to create a CustomButton object with methods setText() and setImage() which would change the button text and image and place multiple CustomButtons into main layout.
Does anyone know how to create a custom layout, place it into another layout(main) and modify its elements from the activity which is bound to main layout?
I would really appreciate your help.
Thanks!
Hey, To create a circular button or rectangular button you can use shape.
It can be done in .xml file.
see this Click Here
If you want programmatic access, you should subclass View and do your work there in java. You can still do the layout in xml, but have the image and text methods that you want. You will then be able to use this in another layout to place your CustomButtons.