how to display a tooltip number over an imageView (like in notification) - android

Is there an easy way to display a tooltip on an imageview looking the same that the number tooltip on a notification icon?
There are no 'number' attribute in ImageView.
Is there another simple way to display a number in a tooltip over an imageview?

Step #1: Put the ImageView in a RelativeLayout.
Step #2: Put a TextView in the same RelativeLayout, as a later child than the ImageView.
Step #3: Give the TextView an appropriate background and text.
Step #4: Give the TextView the android:layout_ attributes you want to position it where you want.
RelativeLayout allows for stacking on the Z axis -- later children float over top of earlier children. And, RelativeLayout allows you to position the TextView in, say, the lower-right corner.

Here a good solution!
Setup ImageView content description (in xml or in the code) and use static methods from CheatSheet.java.

Related

Node can be replaced by a "TextView" with compound drawables

I am just starting on android development. Using the layout editor I added a Image View below the TextView.
By after adding the TextView the following warning was printed:
Node view can be replaced by a "TextView" with compound drawables
This tag and its children can be replaced by one <TextView/> and a compound drawable A LinearLayout which contains an ImageView and a TextView can be more efficiently handled as a compound drawable (a single TextView, using the drawableTop, drawableLeft, drawableRight and/or drawableBottom attributes to draw one or more images adjacent to the text). If the two widgets are offset from each other with margins, this can be replaced with a drawablePadding attribute. There's a lint quickfix to perform this conversion in the Eclipse plugin. Issue id: UseCompoundDrawables
Please help me resolve this. Thank you
The warning says "can be replaced by" not "should be replaced by". So you can ignore it. Not every ImageView and TextView combo can be replaced by CompoundDrawables. Even then let me if you want to know, how to do this, I have described it below.
TextView tag comes with 4 compound drawables, one for each of left, top, right and bottom.
Just add below line to your TextView.
android:drawableLeft="#drawable/up_count_big"
Or in java code, you can do it like this:-
mTextView.setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom);
where left ,top ,right and bottom are all drawables.
See TextView#setCompoundDrawablesWithIntrinsicBounds for more info.

Align a layout top of a image that is centered

I have a relative layout, inside of it is a ImageView that is centered in its parent.
I want to add a share up to the image. If I put this attribute android:layout_alignTop="#+id/myImage" the button will appear over the image. I want to be upper than this.
Use
android:layout_below="#+id/shareId"
in your <ImageView> tag. Or
android:layout_above="#+id/myImage"
in your share's View tag depending on what works better for you. If this doesn't fix it then please post the xml and a picture of what you want/have if possible.
RelativeLayout Docs shows the different properties that can be used.

Android XML: Good examples to use gravity rather than layout_gravity

I have done some basic xml layout from the Internet and I am confused as to what android:gravity would be used for vs android:layout-gravity. The UI designer seems to respond well when I change the layout_gravity, but I get no response to the regular gravity? What is up with this?
Is this similar to layout parameters with fill-parent and match-parent? one is gone now.
android:gravity is a statement from a parent to its content, indicating where the content should slide within the available parent space (if there is room for such sliding).
android:layout_gravity is a request from a child to its parent, asking that it be slid in a certain direction (if there is room for such sliding).
layout_gravity - It contains and it belongs to component's parent layout. Like if you set one TextView in LinearLayout, LinearLayout's width is fill_parent, but TextView basically will set at left-top. So now if you would give layout_gravity=right then your TextView will be shifted to top-right corner. But the text will not change its place. i.e. you had been wrote "Hello world" then "hello world" will not be changed to right, but its parent textView will be changed to right. So here in this case it will belongs to LinearLayout, means parent Layout.
gravity- It contains and it belongs to TextView as per above explanation. if you will give gravity="right" then "Hello-world" text will go to right-top corner of TextView not LinearLayout.

Android, Specify what View should be shrinked if no space

I've got next problem.
There is ImageView and button panel below it. I want ImageView to be as large as it needs, but if there is no enough space button panel should be present on screen and Imageview should be shrinked. What is the best solution for that?
Have a look to the android:layout_weight attribute.
What does android:layout_weight mean?
In case there is only 2 views in one layout (ie. Imageview and button) you can put both view in linearlayout and give value 1 for imageview weight layout (and doesn't give any value for the button)

Imageview floating left

How can I create ImageView floating to the left of the textView, something like html:
<div>
<img src="src" style="float:left"> Text here.....
</div>
You have two options:
With LinearLayout, setting the orientation to horizontal so the image is first and then come the rest.
With RelativeLayout, there you can indicate the position of a element relative to another with the attributes of the style android:layout_toLeftOft, android:layout_toRightOf, android:layout_below or android:layout_alignParentTop, ...
However, it is not so flexible as CSS for some actions and, for example, wrapping text around an image is not so easy to achieve.
There's really no concept of floating elements in Android, but you can easily put an image to the left of some text using the drawableLeft attribute of the TextView. Example:
Otherwise, for more complicated layouts, parent views determine how their children are laid out. For example, instead of the concept of a div which simply wraps it children and uses the float and display attributes of the children to determine how things look, Android has more complex parent views (ViewGroups as they are called, since that's the super class) to control things.
Check out the docs for LinearLayout and RelativeLayout for some examples.
The positioning of views depend on the kind of layout you use. In case if you are using a RelativeLayout and you want to float your view(in your case the ImageView) which is within this Relativelayout, you can use the attribute of the ImageView (android:layout_toLeftOf="") specifying the view id of your textview between the double quote.

Categories

Resources