How to support different screen size in android using dimensions?

喜你入骨 提交于 2021-02-08 10:00:11

问题


I am developing an android app where i have 40 xml layouts.

Previous projects i was using multiple folders to support multiple screen but now i have 40 layouts its difficult to create different folder.

i heard about dimensions but i don't know how to achieve that .can any one provide some code or example

Thank you

Before asking this question i read following answer but it is asked in 2013.

Different resolution support android


回答1:


If you have ten Buttons and one TextView in your layout, then the first thing to do would be to put the values (in dp) for the UI Elements in the 'res/values/dimens.xml' file, for example:

    <dimen name="btn_width">64dp</dimen>

To support different screen sizes or orientation changes, you might want to have alternative values. These would go into the respective 'values-.../dimen.xml' file.

In the layout xml file, you could write:

 <Button
    android:layout_width="@dimen/btn_width"
    android:layout_height="@dimen/btn_height"
    android:text="New Button"
    android:id="@+id/button"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"/>


来源:https://stackoverflow.com/questions/32133266/how-to-support-different-screen-size-in-android-using-dimensions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!