Getting page dimensions - nativescript

On navigating to a new page, how do I get the dimensions of the page - the client/layout area only - exclude the action bar if present.
Will I get the same notification when the device orientation changes?
Thanks.

Every view in NativeScript has a method call getMeasuredHeight() as well as getMeasuredWidth(). You can get the page dimensions like this:
var pageHeight, pageWidth;
pageHeight = page.getMeasuredHeight()- page.actionBar.getMeasuredHeight();
pageWidth = page.getMeasuredWidth()- page.actionBar.getMeasuredWidth();

Related

How to move a view based on validation uikit swift

I have a validation inside of my app and a textfield both are located on different areas of the same screen.
Textfield is on y = 200
Validation Button is on y = 800
Whenever I am at the point of the validating of y = 800 and my textfield is empty I need to automatically scroll on the background to y which is 200 from y = 800.
In short
if textfield is empty I need to go to this specific place (y=200) which is located in the beginning of the app.
I am not sure how to do it in uikit.
If you are using UIScrollView, you can call scrollRectToVisible and pass the textField's frame as parameter to this function.
scrollView.scrollRectToVisible(textField.frame, animated: true)

SAPUI5 Panels - Controlling position of content

I have a number of Panels which, when expanded, show the corresponding questions for that particular 'Category'
The issue I have is, say for example I answer the questions for the 1st panel, the content will scroll down, eventually hiding the panel... fair enough.
However, when I click on the Next Category (Production Area), I need to the page to scroll back up to the first question in the Category, or maybe even just display the selected category at the top of the page.
Is this possible?
Currently, the user has to continually scroll back if when they select the next Category.
You can achieve it using scrollToElement()
var oPage = sap.ui.getCore().byId("pageId"); // you page ID
var oList = sap.ui.getCore().byId("ListId"); // element ID to which it has to scroll
if (oPage && oList) oPage.scrollToElement(oList, 1000);
Execute the above code inside the panel event expand.
you can try to use this control instead which suits your needs
https://sapui5.hana.ondemand.com/#/entity/sap.uxap.ObjectPageLayout
After trying everything, this is what worked for me.
onExpand: function (oEvent) {
if (oEvent.getParameters().expand) {
var focusID = oEvent.getParameter("id");
var elmnt = sap.ui.getCore().byId(focusID);
elmnt.getDomRef().scrollIntoView(true);

How to partially display Navigation Drawer

Normally in Navigation Drawer when we click on the top left corner icon the Navigation drawer will be opened as shown in the screen1.
I need to display Navigation drawer partially as shown in the below screen 2 while the screen(Activity) is launched initially without firing any event.
Can anyone please help me.
Thanks
Ravi
set the width for ListView dynamically...
mDrawerLayout = (DrawerLayout) view.findViewById(R.id.drawer_layout);
mDrawerList = (ListView) view.findViewById(R.id.top_sectionlist);
int width = getResources().getDisplayMetrics().widthPixels/2;
DrawerLayout.LayoutParams params = (android.support.v4.widget.DrawerLayout.LayoutParams) mDrawerList.getLayoutParams();
params.width = width;
mDrawerList.setLayoutParams(params);

How to resize a sublayer in view with in Swift?

I have a session with AVfoundation to record a video and take phootos, and this session is necessary add to a view to show this. I add this with this code:
var previewLayer: AVCaptureVideoPreviewLayer = AVCaptureVideoPreviewLayer.layerWithSession(self.session) as AVCaptureVideoPreviewLayer
previewLayer.frame = self.imagePreview.bounds
self.imagePreview.layer.addSublayer(previewLayer)
imagePreviw is the UIView.
This is adding correctly, but the session camera only show in a part of the view, how can I show this in all view?
I add picture to show the problem and that I want:
I think the frame is correct but I think you should set the videoGravity like this:
previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;

images wont unload - please assist

I have some code here that when an image (which is my button) is clicked, a new image randomly appears. This is due to a table I created with some images inside.
local animalPic
local button = display.newImageRect ("images/animalBtn.jpg", 200, 200)
button.x = 250
button.y = 50
local myPics = {"images/animal1.png", "images/animal2.png"}
function button:tap (event)
local idx = math.random(#myPics)
local img = myPics[idx]
local animalPic = display.newImage(img)
animalPic.x = contentCenterX
animalPic.y = contentCenterY
end
button:addEventListener ("tap", button)
The problem with it is the graphics just keep piling up when I click the button. The correct behavior should be -
Button is clicked and an image is shown while removing the previous image. How do I incorporate this behavior? I already tried the removeSelf command and it doesnt work......Any help appreciated.
You declare animalPic each time you enter function. You should declare it once and then remove it and replace it by another.
It should be:
local animalPic
function button:tap (event)
local idx = math.random(#myPics)
local img = myPics[idx]
animalPic:removeSelf()
animalPic = nil
animalPic = display.newImage(img)
animalPic.x = contentCenterX
animalPic.y = contentCenterY
end
When you call display.newImage(), you are adding a new image. The problem is that you need to remove/hide the original one. Perhaps you really need two objects - one for the current image and one for the tap event. When the tap event occurs, hide the old image and display the new one. An alternative would be to load all the images in their own imageRects and then toggle them on and off.

Resources