I know of a couple ways to do this (neither of which I like) - so I'm turning to the experts at SOF.
I want to use the ProgressBar. The catch is that I want to use this as the image/background for my ImageView. Is there a way to do this? I started trying this with drawable but I wasn't sure how to go about it exactly.
You can use a ViewSwitcher to switch between the ImageView and a ProgressBar. You can set the ProgressBar as the first child, and when you are done loading the image, you can switch to the ImageView.
Use FrameAnimation drawable as the source of the ImageView
or you can rotate it use TweenAnimation.
Animation Resource
<LinearLayout
android:orientation="horizontal"
... >
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#android:style/Widget.ProgressBar.Small"
android:layout_marginRight="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/loading" />
</LinearLayout>
Related
I am new in Android development.I created a simple project with a simple button.I'd like to set image as background (see image). I've used android:src="#drawable/id_image" and android:background="#drawable/id_image2" but the image does not appear on the entire surface of button.Any help would be appreciated
Android, you can use android.widget.ImageButton to display a normal “Button“, with a customized background image.
<ImageButton
android:id="#+id/top_bar_btn_right_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:src="#drawable/ic_filter" />
You might use android:src and android:background for adding two images.
when you add your button , you just go to the menu of properties and choose background / drawable and choose your image
You can try something like this
<RelativeLayout
android:layout_width="250dp"
android:layout_height="400dp"
android:background="your_background_goes_here"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:centerInParent="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="your_icon_above_background"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text_for_your_image"/>
</RelativeLayout>
I have an image button shape like a 'star' and i what the clickable area to be only the 'star' but instead of that i have a transparent square clickable area around the 'star', can anyone please tell me how to remove the square bcoz the next 'star' it's close and the square overlaps the first 'star'.
thank you so much
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:layout_weight="1"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="190dp"
android:layout_marginBottom="180dp">
<ImageButton
android:id="#+id/star"
android:layout_width="120dp"
android:layout_height="120dp"
android:background="#drawable/star"
/>
Instead of ImageButton you can user ImageView and make in clicable.
Set
android:background=#android:color/transparent
and insert
android:src=#drawable/star
Or just use an ImageView instead, because you can have OnClickListener on both, therefore they could also function as described in your question.
You can use:
android:background="#null"
in the imageButton tag.
May i ask how to put icon on my button like the image below?
And also where can i have resources or sample resources of buttons like this?
You'll need to set the drawable to the left of your Button. Either via xml or programmatically.
Either create a button and set a compound drawable or create an ImageButton.
<TextView android:id="#+id/login_with_facebook"
android:layout_width="100dp"
android:height="48dp"
android:text="FACEBOOK"
android:gravity="center"
android:drawableLeft="#drawable/facebook_icon_48_x_48"
android:clickable="true"/>
<Button android:drawableLeft="#drawable/image"
android:text="facebook"/>
If u want space between image and text, then give drawablePadding Like:
<Button android:drawableLeft="#drawable/image"
android:text="facebook"
android:drawablePadding="10dp"/>
using RelativeLayout it can be done easily. here I got snippet for you,
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
<Button
android:id="#+id/fb_logo_button"
android:text=""
android:background="fb_logo"
android:layout_height="match_parent"
android:layout_width="match_parent"/>
<Button
android:layout_toRightOf="#id/fb_logo_button"
android:id="#+id/fb_text_button"
android:text="Facebook"
android:textAlignment="center"
android:background="#android:color/holo_blue_bright"
android:layout_height="match_parent"
android:layout_width="match_parent"/>
</RelativeLayout>
this will ensure that whatever your images are for respective DPIs, it will align this layout to center horizontally. Within this layout logo will be always to left of text as in picture.
This is applicable when your parent is also a RelativeLayout. If you got LinearLayout as parent then in above RelativeLayout tag change android:layout_centerHorizontal="true" to android:layout_gravity="center_horizontal"
I can't test it in eclipse as I'm out of home. Try this and let me know. Thanks.
i want to make animation with two pictures, but they are steretched. When i open this image like src in imageView- all is ok(image 1) , but when i run animation - it steretced(image 2).
<ImageView
android:id="#+id/iv_exercise_info"
android:layout_width="fill_parent"
android:layout_height="238dp"
android:layout_gravity="center" />
I try to set scaleType fitXY, but it does not help me. Sory for my english.
I think layout defined for imageview is where the issue is. Try this.
<ImageView
android:id="#+id/iv_exercise_info"
android:layout_width="wrap_content"
android:layout_height="238dp"
android:layout_gravity="center" />
Hope this solves your issue
Use following :-
android:id="#+id/iv_exercise_info"
android:layout_width="fill_parent"
android:layout_height="238dp"
android:ScaleType="CENTER"
So I'm working on making a design for my app and I need to put a imagebutton directly below an imageview. But since my imageview has a border around it with a drop shadow I need to hide (shift up) maybe 10 pixels of my imagebutton behind my imageview. Here is a quick drawing of what I want.
I hope that makes sense. I've been messing around with all kinds of different arrangements but I cant get what I want. Any help would be greatly appreciated.
First of all use a RelativeLayout. Add first the ImageButton and then the ImageView, in this way the ImageView will be on top of your ImageButton. Then you should set on your ImageButton the following :
<ImageButton
....
android:layout_below="#id/ImageViewId"
android:layout_marginTop="-10px" />
Use relative layout as said. Refer
http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html
for more positions and easy design.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/Imageview"
android:layout_marginTop="-16dp" />
<ImageView
android:id="#+id/Imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="46dp"
android:adjustViewBounds="true"
android:contentDescription="#string/description_logo"
android:src="#drawable/imagename" />
</RelativeLayout>