I am new in android development. I want to set margin & padding in Xml,not in dp or px but in percentage. Is there any way to do this?
相关问题
- 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
If you are trying to share sreen width between your controls in percentage. Best way to do that in android is using
weight
property for them. Check following URL for more details.Android Layout Paramas guide
regards, Aqif Hamid
It became possible with Guidelines introduced in ConstraintLayout.
Here's the example of TextView placed at 60% of screen width and 25% of screen height:
Though it is quite late, it can be done with Android percentageRelativeLayout https://developer.android.com/reference/android/support/percent/PercentRelativeLayout.html One can use percentage with some attributes but not all are supported. Like padding is still not supported in percentage whereas margin is.
it is not possible, though You better do it by taking width and height of screen like below in your java code, and
then calculate your margin from screen size, and set it by
this way you can set margin depending on the screen size not fixed for all screen, and basically it is like setting in percentage but from Java code.