I tried this piece of code:
scrollObject = dict(direction="down", text="some_text", element=appium_driver_elem.id)
self.driver.execute_script("mobile: scrollTo", scrollObject)
But I am getting an error saying:
"appium_driver_elem does not have attribute like id" or sometimes nosuchelementexception.
What is the simplest way to scroll with appium in android using python? Any full test examples?
self.driver.swipe(470, 1400, 470, x, 400)
self.driver.swipe(start_x, start_y, end_x, end_y, duration)
start_y value represents bottom Y value & end_y value represents top Y value of the screen in your app.
Since to scroll we hold screen at bottom & move up.
value of x depends on how much you wish to scroll in one shot.
Example: To scroll to the bottom, try 300. To scroll little x can be 1200
Still haven't found an answer. So maybe you need to play a little bit rough.
You can use the self.driver.scroll(self,SrcElem,DestElem) function to swipe screen from bottom to top and check the element you seek.
Or You can also try to do
from appium.webdriver.common.touch_action import TouchAction
...
action = TouchAction(self.driver)
action.press(start_element).move_to(end_element).release().perform()
Actually, that's how scroll() function works. Once, I had an issue with self.driver.scroll(), so this can also be a workaround.
Related
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)
I am using
action = TouchAction(self.driver)
action.press(self.element).perform()
height = self.element.size["height"]
action.move_to(x=0, y=height*int(height_multiplier)).perform()
to scroll in android.But if i give height_multiplier as 1 or 2 it works fine.Scroll downward too.But when i give it -1 or -2 expecting it too go upwards it gives an error
The coordinates provided to an interactions operation are invalid.
I have already tried scroll(element1,element2) but it doesnt scroll ,just flicks to end.also driver.execute doesnt work as well as mobile:scroll is not yet implemented for android.Does anybody know a workaround?Partial scroll is what i want precisely
I have implemented scrolling up as follows: driver.swipe(0, scrollStart, 0, scrollEnd, 2000) where scrollStart < scrollEnd. Both values still must be positive to fit in the resolution range.
I just started using SpriteBuilder and was wondering if something like “autolayout” (in a basic form) was possible for the apps? You see I have made this simple layout ( http://cl.ly/Szs3 ) containing a header (blue-ish) and body (red).
Now what I want is that the header has a fixed height (it has 100% percent width, so that goes wel) and the red block “fills” the rest of the screen. So when the device is a taller device more content at once can be shown.
Is this possible? And if so, how could I acchieve this.
Yes there is such an option, yet the naming is a little bit different.
I uploaded my example project to this GitHub Repo: https://github.com/MakeGamesWithUs/Spritebuilder-Simple-Autosizing
Your top container needs a static height, and a relative position and a Y Anchor Point of 1. This way the top container always has a size of 100 points and is always positioned at the top of the screen:
Your bottom container needs a height inset of 100, this means your container will use the complete height of the parent container, except for 100 points at the top:
You can take a look at:
Auto Layout[About] Constraints
UIStackView
This question is very specific, What I am trying to do (with a list view) is described in great detail in the following article: http://www.pushing-pixels.org/2011/07/18/android-tips-and-tricks-synchronized-scrolling.html
Thanks #kaushal trivedi for the link
Details:
I have an android application I am working on that uses a list view with a custom adapter. The Listview Contains a Custom header of a non-fixed height. Also please note that the list items are also of variable height. My goal is to mimic the effect produced in the latest gmail app (as an example) where when you are viewing an email, and scroll past the header, it sticks to the top of the screen just under the action bar and the content continues to scroll under it. What I would like to do, is stick the bottom half of my header to the top of the screen.
My initial reasoning was to create an invisible view fixed in the desired location, and when the user scrolled to or past that location, make the view visible. The issue in this logic, is I need the exact pixel scroll height, which after many attempts I have determined very difficult to do. The exact issue I ran into is, it is not possible from what I can gather to retrieve the pixel level Y-scroll in an onScroll event, I have only been able to retrieve the value in the onScrollStateChanged event. Which as described above will not achieve the desired functionality.
Working with the onScroll event "int firstVisibleItem, int visibleItemCount, int totalItemCount" parameters is also not an option because of the fact that the content I want to "stick" is not the size of a list item, but a fraction of the size of the variable height header.
Is there a correct way to accomplish this effect? My current minSDK level is 10.
Update 10/10/13
I made some progress. The following code syncs the Y position floating view I have on the screen with the list view. b is the view I am setting just as an example.
NOTE: This is used in the onScroll event of the list view.
View c = view.getChildAt(0);
if (c != null) {
int currY = c.getTop();
int diffY = currY - lastY;
lastY = currY;
b.setTop(b.getTop() + diffY);
}
Now the issue is, the header of my List is a non fixed height as I said earlier. So I need to get the height of the header and apply an offset to "b" to place it at the bottom of the list header floating above the list.
This is the code I've tried so far.
header.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
The issue here us header.getMeasuredHeight(); always resolves to the same value no matter how tall the actual height is.
I understand I cannot get the height until after it is displayed. Is there a way I can get that value and set the offset after it is rendered?
Update 10/11/13
I Answered my last question as soon as I woke up this morning.
While the View.measure() code was returning a height. It appears to be the default height of the view, assuming there was no text (that would ultimately stretch the view). So I used the below event to listen for when the view is displayed, and then record its actual height (which works exactly as I had hoped :) )
ViewTreeObserver vto = header.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
b.setY(header.getMeasuredHeight() - 80); //80 is a temp offset
}
});
I have to go to work soon and being that I have still not fully achieved the desired effect, I will not mark this as answered yet. Hopefully I will be able to sit down and finish this in the next day or two. I am still open to suggestions on better ways of doing this.
Okay, so after a lot of time and research, I have found an answer to my question.
First off, Thank you #kaushal for this link: http://www.pushing-pixels.org/2011/07/18/android-tips-and-tricks-synchronized-scrolling.html
My solution ended up being somewhat complex. So instead of trying to describe it here, I made an example app and posted it here: https://github.com/gh123man/Partial-Header-ListView-Scroll-Sync
The specific file containing the code for the solution is here: https://github.com/gh123man/Partial-Header-ListView-Scroll-Sync/blob/master/src/com/example/partialheaderlistviewscrollsync/MainActivity.java
I am trying to dynamically create and then move an image in an Android activity. However, the setX() and setY() methods seem to not work correctly. It correctly sets the position of an image when it is first created and placed, but any attempt to update it results in the image being placed in the wrong spot. For instance, the image moves on the following code:
ImageView image;
RelativeLayout layout = (RelativeLayout)findViewById(R.id.activity_this);
if(action == MotionEvent.ACTION_DOWN){
image = new ImageView(MyClass.this);
layout.addView(image, width, height);
image.setX(206);
image.setY(206);
}
else if(action == MotionEvent.ACTION_MOVE){
if(image != null){
image.setX(206);
image.setY(206);
}
}
On ACTION_MOVE the image is moved even though the x and y position values remain the same. The parent of the image remains the same. The size remains the same. If I get the x and y values it will still say 206, but it is not placed at (206, 206) on the activity anymore. I am lost as to why this is happening. I can't find any indication that the image has been altered except for it physically changing location.
Really, this shouldn't be happening. Alternatively, try setting another variable and setting x and y to it, or get x and get y and add a 0 to each one of them for same location.
As stated in Android - Use of view.setX() and setY in api 8, if you have searched, there is another solution that also works even before api 8.
LayoutParams works like this -
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); //WRAP_CONTENT param can be FILL_PARENT
params.leftMargin = 206; //XCOORD
params.topMargin = 206; //YCOORD
childView.setLayoutParams(params);
There is more information there. I hope this helps
Run into the same issue. View.setLeft(int)/View.setTop(int) worked for me.
Note that since the original post of this answer things changed and on the more recent android versions it may produce unexpected results while it did the trick for me on older versions. So if you are targeting older devices (android 3.0 and below) this may help but for a more generic solution please consider other answers here as well.
From the docs, setTranslationX is:
Sets the horizontal location of this view relative to its left position. This effectively positions the object post-layout, in addition to wherever the object's layout placed it.
And setX is:
Sets the visual x position of this view, in pixels. This is equivalent to setting the translationX property to be the difference between the x value passed in and the current left property.
Thus you can think of setTranlsationX as a relative offset: move 3 pixels left of where you normally would be. And setX is a fixed position: move whatever you have to so that you end up drawing at coordinate X.
Is your activity in full screen mode? If no try to make it to full screen and it should solve your problem.
Pretty late to answer, but if someone else is facing the same problem. This fixed it for me it was the paddings in the layout file:
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
As someone who actually facing this problem, I have solve this issue by removing any padding in the parentView. The padding seem cause a change in the layout size