Android GestureOverlayView limiting paintable area - android

In GestureOverlayView is there any way to limit paintable area. ie in the whole View i want some margin that is not paintable, with the view(GestureOverlayView) covering all the available area

you can try to apply padding in your view. probably in your layout xml, or via code View.setPadding(int left, int top, int right, int bottom)

Related

What's the best way to get or calculate usable screen space

I trying to get the usable screen space for my app. This would be the space between the Action/Tool bar and the Navigation bar.
Reason I'm needing it. I have six buttons in a constraint layout chained together vertically. At run time I need to resize the buttons. The app has a fixed landscape orientation.
Ultimately I want to constrain the the bottom button of the chain to the bottom parent or nav bar (if it exists) and the top button to the action/tool bar.
I've found that there's an attribute resource for the action bar/tool bar that I'm constraining the top of the chain to.
For the bottom, my thought is to constrain the bottom button with a constraint guide. I just not sure how to find the screen position to position it at.
There is one more way of doing this, if the previous answer doesnt work for whatever reason. In your layout editor, put buttons on the constraint layout and constrain them one to the other. Set constraints to be fixed, for example 8dp. The first button is constrained to the top of root layout, the last to the bottom. Lastly set the height of buttons to "match constraint". Am on mobile so I cant copy any xml, but this should force the height to be ruled by the dimension of root layout and lenght of constraint
Steps:
Get window height
resize images proportional to that height
add this code somewhere after setContentView or after inflation:
// root layout is the constraint layout which holds the buttons
rootLayout.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
#Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
int rootHeight = v.getHeight();
int btnHeight = rootHeight/6;
btn1.getLayoutParams().height = btnHeight;
btn1.requestLayout();
btn2.getLayoutParams().height = btnHeight;
btn2.requestLayout();
// and same for the rest of your views
}
});

MPAndroidChart chart padding

I can't seem to enable padding on the horizontal BarChart in MPAndroidChart... Like on the screenshot below..the word commentary is cut off..even on tablets, both orientations e.t.c
Have a look at the viewport documentation of the MPAndroidChart library.
There you find a method called setExtraOffsets(float left, float top, float right, float bottom) that allows to set additional offsets (as you require) for the chart.
chart.minOffset = 0f
it will remove space on top/right/bottom/left, but it have 1 problem. A half of the HIGHEST label on left/right axis will above (overflow) another view on top)
chart.setViewPortOffsets(left, top, right, bottom)
it help us set the space in top/right/bottom/left but from the axis not from the label (eg: if we set left = 0 we will not see the label on the left). so if I only want to set the space on top only, this function is not suitable
chart.setExtraOffsets(left, top, right, bottom)
chart.extraTopOffset
chart.extraBottomOffset
chart.extraRightOffset
it helps us set space to top/right/bottom/left but it is the EXTRA space so to make it look as same as the design (eg: 40dp), I use
chart.extraTopOffset = getDimension(R.dimen_40dp) - chart.minOffset
Set this function in the getFormattedValue (if you use this) or in any suitable area.
bar.zoomOut()

android place a view in a specific place above an image

I want to create a layout that contains an image on top of which I want to place many images and TextViews. I know how to place images on top of one another using RelativeLayout, but how to align them in a desired way? Eg I want an image to be exactly in a place where my “background” image has a specific black circle. Playing with values like android:layout_marginTop etc does not seem to do the effect in every screen.
So which is the proper way to handle these issues?
EDIT:
I cannot upload the images, but I uploaded a very simple sketch of what I want here:
http://imageshack.us/photo/my-images/715/buttonlayout.png/
all the buttons have also Icons and text (which must be a textview so that I can change it programmatically if need be)
You have to create a custom layout that places the image specifically where you want them relative to the size of the parent view. If you choose, you can override the LayoutParams and apply custom attributes to them for your custom view to read.
Anyway, to specifically place an item, say 30% down from the top and 20% from the left, you would overwrite onLayout().
#Override
public void onLayout(boolean c, int left, int top, int right, int bottom) {
super.onLayout(c, left, top, right, bottom);
int width = right - left;
int height = bottom - top;
View v = getTheChildView();
int viewL = left + (int)(width * .2f); // The left pixel is 20% down the total width of the parent view
int viewR = viewL + v.getWidth(); // The right pixel is the left pixel plus the measured width of the child view itself
int viewT = top + (int)(height * .3f); // The top pixel is 30% down the total height of the parent view
int viewB = top + v.getHeight(); // The bottom pixel is the top pixel plus the measured height of the child view itself
v.layout(viewL, viewT, viewR, viewB);
}

Android Layer_Drawable as a button

I have a button.
The button is constructed from the StateListDrawable (made of 3 9-patch images).
I need to add an extra drawable that will reside on the button's right side, and i need it to be aligned with the button's right side.
I tried to use the following:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/blue_back_button_drawable" />
<item>
<bitmap android:src="#drawable/filter_by_button_v_mark" android:gravity="right"/>
</item>
</layer-list>
it didn't work and the V image is indeed aligned right but it has a diff from the button's right side. here's a snapshot:
I want the image to be aligned with the button's left, the only way right now i think i can do it is:
inherit button, in onLayout AFTER the width has been set get the right edge.
get the background drawable (layerDrawable)
calc the button's width minus the v image width and set it as left margin in the drawable.
I should not mention this sounds horrid :-) i hoped there's a better way. Oh the reason it's not part of the image is that i need to know it's width so i can calc the text padding so it wont be hidden by the button's text and because it's not so nice looking as a 9-patch.
Seems like there was no proper solution to this. layer is for static and not 9-patch images apparently, or so it seems.
So i extended Button, changed it's on Draw, i have to use Canvas.restore() to break out of the margins that pushed my edges down and put my image in the upper right corner...
here's the code:
#Override
public void setPadding(int left, int top, int right, int bottom) {
right += mImageWidth;
super.setPadding(left, top, right, bottom);
}
private void setVImageDrawable(Drawable d) {
mVImageDrawable = d;
mImageWidth = mVImageDrawable.getIntrinsicWidth();
}
#Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if( mVImageDrawable != null && mIsMarked){
//for some reason the clip binds us to position with margins, which is not so good for us.
//we need to save the clip, restore the canvas to pre clipping mode, do what we need then
//put the canvas back to it's previous clipping state.
Rect bounds = canvas.getClipBounds();
canvas.restore();
int right = getRight();
int left = right - mImageWidth;
int top = getTop();
int bottom = top + mVImageDrawable.getIntrinsicHeight();
mVImageDrawable.setBounds(left, top, right, bottom);
mVImageDrawable.draw(canvas);
canvas.save();
canvas.clipRect(bounds);
}
}
If i don't break out the original canvas iget 'pushed down' by any margins i add, it may also be fixed i think using xml property that specifies if children should be clipped on the layout containing this button, but i find that lame solution as it makes my button dependent on our conditions.
The image itself i get from XML using new attributes and style and theme i declare.
Hope it'll help some ppl out there.

how to set image's margin top using coding not xml in android

i am using android:layout_marginTop="100dip" in my imageview,i want to set margin top to each image depending its height using coding not using xml,how can i set image's margintop?
Use
public void setMargins (int left, int top, int right, int bottom)

Categories

Resources