cannot figure out how withIconOffset works - android

I have been messing with withIconOffset to move center of anchor to exactly bottom of the icon.
It says "Positive values indicate right and down, while negative values indicate left and up", what does it mean? passing some values does move my marker around but cannot postion it correctly.
Also tried to divide my png icon height in half and move it up by that amount but it goes too far up.
.withIconOffset(arrayOf(0f, -image.height/2f))
Im using .withIconSize(2f) too, will it have any effect on offsets?

my bad, forgot to convert image height to dp.
something like this works fine
val Int.dp: Int
get() = (this / Resources.getSystem().displayMetrics.density).toInt()
//...
.withIconOffset(arrayOf(0f, -image.height.dp/2f))`
edit:
I also found another way .withIconAnchor(Property.ICON_ANCHOR_BOTTOM)

Related

Android MP Chart library get X-axis height

Let's say I have an Activity containing a ChartView (blue rectangle)
Now, I want to place another View on top of it that will stretch from the X-axis all the way to the top of ChartView.
I tried to do that by setting the margin-bottom equal to the height of the X-axis (red area), but I don't know how to get its height
How can I achieve this effect? Is there a way to get X-axis height in Android MP Chart? Or maybe there is a walkaround that will have a similar result?
Desirable outcome (the gray area is a view placed on top of the chart):
chart.getXAxis().mLabelHeight returns the height of x-Axis by pixel.
You can get it after OnGlobalLayoutListener, because it is calculated after x-Axis is drawn.
----------Updated Jun 22nd
another way is to use "getHeight() - mViewPortHandler.contentBottom()", but mViewPortHandler is protected, so an extended chart is necessary to provide access to mViewPortHandler

Android bottomsheet - How i can set onSlide offset to 1 when card state is half_expanded?

i have set my bottomsheet ot be half expanded using the folloiwng code:
bottomSheetBehavior?.isFitToContents = false
bottomSheetBehavior?.halfExpandedRatio = 0.6f
and it works fine. The issue is I have some content that changes alpha property as the card slides to halfway point. At the halfway expanded point, the alpha of the content should be 1. it works great without using isFitToContents = false, but when I do use it to half expand the card the slideOffset does not end at 1, for example, it ends at .019 because I just moved up a little bit to reach halfway expanded.
Therefore to my issue: How to make the half_expanded state slideOffSet end at 1 ?
another approach: if I could know the very last half expanded offset value then I can use that ahead of time as a scale factor. let's say that value was called halfExpandedOffSetEnd. then I could create a scale factor like this:
val multiplier = 1/halfExpandedOffSetEnd
I could then multiply that by all my offsets to get the desired effect. but how would i get the very last offset value for half expanded ahead of time?

how to scale image between 2 views with given coordinates in android

In my application I have a requirement to animate an image (this image view has an arrow set as source).
I am unable to figure this out how I can achieve this.To solve this i got x and y coordinates of second view that is rectangle after getting coordintes i am setting
scaleX() of image view that is purple line but I am not geeting desire out put because it stretches to the whole screen along x-axis
here is the code what i tried is
int x = (int) imageView.getX();
imageView2.setScaleX(x);
here imageview is rectangular box and imageview 2 is the purple line
Why you dont try with scenes? It's exactly what you need.
http://developer.android.com/training/transitions/scenes.html
I think you are getting the correct output when using the above code. Scale is defined against initial dimensions. And you would need to use something like this
dist = box.getX() - circle.getX()
and your scale would be
imageView2.setScale(dist/distInitial)
where distInitial you compute it at creation time using the dist formula.
You might need to change the position because it is scaled around the center of it (i.e. a smaller scale shrink margins to center of image)
You might want to perform this operations using a Canvas. It might be more efficient.

Redrawing clipped content in Android View after moving into bounds

Within Android, I'm trying to move a TextView from outside the parents bounds into view, but the contents never shows up, or remains clipped if it was partially within the bounds already.
Initial situation at start
Situation after animation
(Below this is another view, that was completely out of bounds and isn't drawn either)
I have 4 TextViews below each other in a custom Object extending RelativeLayout. Based on a percentage the top 2 should move outside it's bounds and the bottom 2 should move in (from the bottom).
I use the following code to update the properties of each TextView. In this class each variable **positionY* is filled with their initial position from the layout-xml. effect is percentage between 0 & 1. The animation works, but the views aren't drawn again.
public class ActionBarTitleView extends RelativeLayout {
public void updateTransition(float effect) {
float height = getHeight();
titleView1.setY(title1positionY - height*effect);
detailView1.setY(detail1positionY - height*effect);
titleView2.setY(title2positionY - height*effect);
detailView2.setY(detail2positionY - height*effect);
invalidate();
}
}
What I tried
After some researching I found a few hints what the issue might be, but so far none of the tried options had any effect. Below is a list of things I've found on SO and tried.
Calling invalidate() on the RelativeLayout - No effect.
Invalditing the TextViews - No effect.
clipChildren = false for the RelativeLayout - No effect.
setWillNotDraw = false for the RelativeLayout - No effect. (onDraw is being called)
I haven't tried to solve this with a ScrollView, but I don't want to really, cause that adds another layer in the hierachy for something pretty small.
I thought I understood the drawing logic, but perhaps I'm missing something, so I hope someone might be able to point me in the right direction.
What I ended up doing (September 3rd)
Since no real solution was offered, I tried again and came to the following "fix". I set both second labels to Visibility.GONE, but within the original bounds of the container view. Then when I start the animation, I set their correct values, then move them outside the bounds and finally setting Visiblity.VISIBLE. When the animation progresses the labels roll into view as supposed to. So a fix to the issue, but no real explanation why the TextViews aren't drawn again...

Place an imageview on customdialog screen depending on variable

I'm trying to place a small image on the top of a big one in a custom dialog.
I want the small one to be placed in a different place depending on a variable, which I called "pos". It contains a int value from 0 to 100, meaning percentage of the dialog width.
If pos = 0, I want to place the image in the left margin of the big one, if pos = 30 it should be placed in the 30% of the screen, starting from the left.
If pos = 50 I want it to able placed right in the middle, being 100 the maximum value for it and placing it in the right margin.
I include a draft to explain myself a bit better.
I tried with RelativeLayout.LayoutParams but I never get expected output.
Perhaps a simpler strategy is to extend ImageView, then create a custom image using Canvas commands in the onDraw method that draw the bitmap appropriately on the x axis with a background set to match your layout.
You can determine the width of the custom dialog in the the onMeasure method of your custom ImageView, so the returned bitmap (including empty background) can be the correct width, and the position of the smaller bitmap can be correctly apportioned.
Once you've created the class, which will take just a few minutes, you can add it to your XML layout with something like:
<com.domain.yourapp.YourCustomerImageView
android:id="#+id/bitmap_graph"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"/>

Categories

Resources