anyone know how to clear the distance, I don's set any padding or margin params, but that's have a distance,check the images that I present, thank you very much!
I'm the new guy for this,forgive me!
Related
I wonder what's the exact size of the paddingLeft of checkbox, the padding from the beginning of the layout to the beginning of the checkbox, just like the picture shows.
I guess it's almost 7dp or 8dp.
So where can I get the exact number of it?
Sorry I cannot insert the picture in the body.
The picture is here.
paddingLeft picture
I don't really understand what you want, is it calculating the distance from the checkbox to the text or what? instead of using padding, you can use:
android: layout_margin: "8dp"
hopefully this can help you
why there ist no counterpart to getLocationOnScreen? The intuitive way would be setLocationOnScreen... I have an Image View and want to get these coordinates to give the same coordinates to another Image View.
The mentioned intuitive way would be:
int [] location = new int [2];
imageView1.getLocationOnScreen(location);
imageView2.setLocationOnScreen(location);
But this set command is not available. This would be the easiest thing :( Is there any counterpart?
PS: my Image has no margins...
Thanks for help
Because position on screen is controlled by the layout that the ImageView is in, not the ImageView itself. If you need a layout that allows you to position subviews at specific coordinates, try a FrameLayout.
I use the 0.1.1 version of overlap2d. and can not fill my screen. here is my code:
mSceneLoader = new SceneLoader();
mSceneLoader.loadScene("MainScene", new StretchViewport(480, 800));
and in the render meathod:
mSceneLoader.getEngine().update(delta);
And when I run on my note4.
The viewport should probably have WORLD units rather than pixels. You can probably check that in the overlap2d editor.
I think it is shown in this tutorial: https://www.youtube.com/watch?v=bhvHm2sM0qo
Maybe you should try FillViewport ? it does what FitViewport does but fills the screen.
Is this ran on android or desktop? or rather, what is the actual screen size in pixels? (what it outputs when you output Gdx.graphics.getWidth(), Gdx.graphics.getHeight() ) ?
Other thing is, to understand viewports better, take a look at this: https://github.com/libgdx/libgdx/wiki/Viewports
Hope this helps.
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
I am dynamically creating an Editext in my code. i want to position it in my x and y position in my code itself in an absolute layout.
can anyone help me to do this.
Don't use AbsoluteLayout. It's deprecated, and just a bad idea, as it will look differently on screens with different DPIs. Consider using a RelativeLayout instead. If you can give a more specific problem, we can recommend an alternative solution.
Keeping in mind that you shouldn't actually use this, and that using AbsoluteLayout has been indirectly linked to causing cancer, and may also lead to psychosis, here is how you would do this in code assuming you have an AbsoluteLayout with a child EditText in an XML layout:
EditText editText = (EditText)findViewById(R.id.my_edit_text);
AbsoluteLayout.LayoutParams abs_params =
new AbsoluteLayout.LayoutParams(
//width in pixels, or AbsoluteLayout.FILL_PARENT/WRAP_CONTENT
60,
//height in pixels, or AbsoluteLayout.FILL_PARENT/WRAP_CONTENT
30,
//x position with regards to the origin
10,
//y position with regards to the origin
10
);
editText.setLayoutParams(abs_params);
Here are some documentation pages to review:
http://developer.android.com/reference/android/widget/AbsoluteLayout.LayoutParams.html
http://developer.android.com/reference/android/widget/AbsoluteLayout.html
http://developer.android.com/reference/android/widget/EditText.html
I am not responsible for any trauma that may occur as a result of using an AbsoluteLayout. May god have mercy on your soul. :)