How can I change the position of view through code? Like changing its X, Y position. Is it possible?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
Yes, you can dynamically set the position of view in Android. Likewise you have an
ImageView
inLinearLayout
of your xml file.So you can set its position throughLayoutParams
.But make sure to takeLayoutParams
according to the layout taken in your xml file.There are differentLayoutParams
according to the layout taken.Here is the code to set:
I hope it will be helpful to you to set position.
There is a library called NineOldAndroids, which allows you to use the Honeycomb animation library all the way down to version one.
This means you can define left, right, translationX/Y with a slightly different interface.
Here is how it works:
You just use the static methods from the ViewHelper class, pass the view and which ever value you want to set it to.
For support to all API levels you can use it like this:
For anything below Honeycomb (API Level 11) you'll have to use
setLayoutParams(...)
.If you can limit your support to Honeycomb and up you can use the
setX(...)
,setY(...)
,setLeft(...)
,setTop(...)
, etc.I found that @Stefan Haustein comes very close to my experience, but not sure 100%. My suggestion is:
setLeft()
/setRight()
/setBottom()
/setTop()
won't work sometimes.setX()
/setY()
instead. (You might want search more in differencesetLeft()
andsetX()
)You can try to use the following methods, if you're using HoneyComb Sdk(API Level 11).
Parameter x is the visual x position of this view.
Parameter y is the visual y position of this view.
I hope it will be helpful to you. :)