Size and position of GLSurfaceView - android

Actually I have project in which I'm using GLSurfaceView. At this moment this component is placed as main control on whole screen. In this configuration I'm able proper handling drawing functionality.
In next step I want to change size and position of GLSurfaceView. I want to place it in the center of the screen and set width and hight to exact phicical dimmension for example 20mm x 20mm.
Do you have any advices or hints how should I start to introduce this kind of changes to GLSurfaceView?

I want to place it in the center of the screen
You need to set gravity to the parent element like Gravity.CENTER. For example if it's LinearLayout then call linearLayout.setGravity(Gravity.CENTER).
Set width and hight to exact phicical dimmension for example 20mm x
20mm
To calculate size from mm to pixels use:
float mmInPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, 20,
getResources().getDisplayMetrics());
And to set size for GLSurfaceView use LayoutParams:
ViewGroup.LayoutParams layoutParams=glSurfaceView.getLayoutParams();
layoutParams.width=mmInPx;
layoutParams.height=mmInPx;
glSurfaceView.setLayoutParams(layoutParams);

Related

Re: I want to draw a dynamic views based on the X and Y Coordinates and height and width of every view

I want to draw a dynamic views based on the X and Y Coordinates and height and width of every view. Lets take a example like a function hall with lot of tables. so i want to draw all tables like a Button based on X and Y and height and width.
The main problem i am facing here is Android devices has different screen resolutions right. how can i do this any idea please help me.
And i want this view clickable views.
Please see the image below.
You can create a Custom View, you will get the height and the width of the view in pixel on the OnMeasure.
Then you will be able to draw the table at the right place on the OnDraw.
Finally you will be able to detect touch event on your tables on the OnTouch.
Here is a tuto about Custom View, but you can find many others on google.
http://www.intertech.com/Blog/android-custom-view-tutorial-part-2-custom-attributes-drawing-and-measuring/
You could use a GridView with X and Y dimensions. Create an object for each gridViewLocation which can hold int x and int y to save the location, and store the objects in a HashMap as the key to easily obtain the items in a given location. From here, you can use displayMetrics to get the width and height of the screen to edit the dimensions of the objects placed in the GridView.
To adjust for screen size dynamically, you can hardcode the screen size you're testing on (for example, your screen width could be X and your screen height could be Y, find these numbers with displayMetrics when debugging). Then, just calculate X2/X1 and Y2/Y1 (where X2 and Y2 are the screen dimensions of the current device, X1 and Y1 are your dimensions), and multiply those fractions by the initially desired width and height. Set the layout accordingly.

how to calculate position in <translate> tag in android animation?

I am new to android animation and i've been playing with animation in android.
But one thing i just don't get it?
how to set position in tag.
My question is what 50%p means?
Suppose I have a button at some place 1/3 of the top. now i want to move it to bottom of the layout.then move to left bottom then at the center of the layout.
the doc says
Float or percentage. Starting X/Y offset. Expressed either: in pixels relative to the normal position (such as "5"), in percentage relative to the element width (such as "5%"), or in percentage relative to the parent width (such as "5%p").
once see this doc. This will help you to solve your issue.

libgdx custom ViewPort

I need a ViewPort with following the properties :
maintain aspect ratio
fill x axis
always align the top of the screen
cut the bottom if screenHeight < viewPortHeight
Do I need to extend ViewPort or use existing implementations with some configurations, to achieve such behavior ?

Android glsurfaceView - setScaleX() not working/not Stretch the view

This is my final technology issue that i have to complete my 4 month of work on my app.
I will try to be simple as i can,because i need specify solution.
My problem:
In short: i need the stretch my glSurfaceView
I am using custom glsurfaceView,that implement OnMeasure method to set the actual width and height to the surface.
I set the width and height for 1280 and 720 for instance.
then i use openGL and get that pixels with glReadPixel() method to encode video
so far so good.
i add the view in that way :
this.addContentView(this.mRenderSurfaceView, BaseGameActivity.createSurfaceViewLayoutParams());
when :
protected static LayoutParams createSurfaceViewLayoutParams() {
final LayoutParams layoutParams = new LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.MATCH_PARENT);
layoutParams.gravity = Gravity.CENTER;
return layoutParams;
}
Thats what i tried so far:
I want the glsurface to be the actucal pixels that i set in OnMeasure,
that's mean the glReadPixel() function will get the same pixels as i set,
but,I want to scale this surface,without changing to actucal pixels.
when i try this:
this.mRenderSurfaceView.setPivotX(0.0));
this.mRenderSurfaceView.setScaleX(2.0));
It just copy the surface to another place in the screen,without any scale.
What i do wrong?
Please,I don't need to change the actual width and height of this surface.i need it as is-but i have to scale it that the user will see it bigger then the real pixel that i set with onMeasure method.
**i encode the surface to video so any change in width/height will change the pixel that i get in glReadpixel-so just scale is needed.

How to make my android component as size dependent for various display screen sizes?

I am making an android component which allows user to pick date from it. It can be helpful for developer who wants user to select date in his app. In my basic view, I have TextView where date from pop up will be populated into it and I have a button beside TextView. When a User clicks on the button, my component gets popped out and displays Dates. The component gets pops out in a Popup window and shows dates as month view and user also can switch from next-previous months, next-previous years just like we do in Calendar. Check the Image.
http://s15.postimage.org/ujw8py60b/stackoverflow.jpg (Sorry, I couldn't upload an image here because I am not allowed as I am new User here)
Each date is a TextView with the width of 35 and height as 30 set by me. DaysDisplayBar is also of some size set by me. So this component's whole width is 245 and height is around 200. Which is for mobile screen size.
I want to make this component as size dependent for various screen display sizes. For e.g. If it is being viewed on Tablet or Pad, it should be bigger in size than what its size on mobile phone screen. That is, For various displays its size should be changed to some value like max 1/3 of display size or like that something.
What can be the solution for this? According to me, some mathematics is needed here, some formula, equations etc. how about Parabola? Please help, I am dumb in maths totally. Thanks! :D
"Each date is a TextView with the width of 35 and height as 30 set by me. DaysDisplayBar is also of some size set by me. So this component's whole width is 245 and height is around 200. Which is for mobile screen size."
^^ is the problem. Sizes should be defined relative to the layout, not absolute. For example, the calendar has 7 columns (one for each day). Instead of making each one 35px, make each 1/7th of the screen.
SO:
I am assuming a DaysDisplayBar is a row containing 7 TextViews (one for each day). If that is true, why not call it a Week? Either way, The trick is in layout_wieght. Make all elements fill_parent, and all with the same weight of 1. This will evenly distrubate all elements in the parent. In your case, the parent is a DaysDisplayBar.
SO:
set DaysDisplayBar attribute `layout_width="fill_parent"
For each TextViewset attribute layout_width="fill_parent" ANDlayout_weight="1"`
hope that helps!
First of all, make sure you use density pixels (dip) instead of pixels.
Second, you can get the screen width and height, and from there, calculate your component size.
You can get the screen dimensions using the Display class getSize() method:
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point screenSize = new Point();
display.getSize(screenSize);
int screenWith = screenSize.x;
Or you can get the parent view dimensions:
MarginLayoutParams params = (MarginLayoutParams)parentView.getLayoutParams();
int padding = parentView.getPaddingLeft() + parentView.getPaddingRight();
int margin = params.leftMargin + params.rightMargin;
int measuredWidth = parentView.getMeasuredWidth() - padding - margin;
That way you know how much space you have inside the parent view element for your component.
Remember to convert any hard coded value to dip, you can do it this way:
public static int getDensitySize(float size) {
float density = getResources().getDisplayMetrics().density;
return (int)(density * size);
}
You do all of this from your onMeasure method to set your view size, and later on the onDraw you'll use this measure to draw your component.

Categories

Resources