Ability to draw in view mode

Problem and Question:

Currently, I have a pager with a view of only 2 pages / views inside it, which are located next to each other horizontally.

My views are customizable that draw a two-color gradient and an image on top of it with a low opacity / alpha value.

I find that when I sit down on the screen to go from the first view / page to the second or vice versa, the images get squashed. How can I stop this and draw them normally?

Example:

The image on the left shows the first visible visible image, a preliminary swipe ; The image on the right shows two views, halfway through the napkins .

Normal viewSquashed views, as I'm mid-way through swiping

The code:

I have a Drawable variable that I set earlier, overlayImage , that I did nothing but adjust the opacity.

 @Override protected void onDraw(Canvas canvas) { p.setShader(new LinearGradient(0, 0, 0, getHeight(), startColor, endColor, Shader.TileMode.MIRROR)); canvas.drawPaint(p); //Pretty sure the mistake is around these two next lines overlayImage.setBounds(canvas.getClipBounds()); overlayImage.draw(canvas); } 
+6
source share
2 answers

I really think it's in yours

 overlayImage.setBounds(canvas.getClipBounds()); 

line of code. When you get the borders of the clips on the left (top view), it gets the size of the visible area (i.e., a smaller contraction area), and thus the image is drawn into that contracting space.

You probably want to set the boundaries according to the total size of the view on which it is superimposed, and not according to the cropped borders. Use canvas instead of getHeight () and getWidth () and create your own borders.

I really think that you really need to adjust the borders of overlayImage ONLY ONCE in your installation code. The drawing code does not have to set it at all, and then, when the view starts to exit the screen, drawing the overlayImage layer will naturally move along with the rest of the canvas.

+2
source

I think you need to do xml in the drawable-hdpi . Which will contain your shader/linear gradiant .. (for options look here )

 <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:startColor="#474946" android:endColor="#181818" android:angle="270"/> </shape> 

And then you can set xml as background .. which should fix the problem, I think.

(If it doesn't work, try android:shape="rectangle" , which may help)

0
source

All Articles