What does @dimen/activity_vertical_margin do?

后端 未结 2 1164
执笔经年
执笔经年 2020-12-24 03:12

In the following code:



        
相关标签:
2条回答
  • 2020-12-24 03:50

    @dimen/activity_vertical_margin or whatever @dimen/whatever_key_name is a reference to a dimension that probably is saved in your projectname/src/main/res/value/dimen.xml file

    In android you can save several values for example dimensions, strings, integers, drawables...

    Here you can find more information about it

    0 讨论(0)
  • 2020-12-24 03:51

    @dimen refers to dimension and it's a file where you define dimensions to use them later from in any layout file.

    It's located in res/values/dimens. Here's what a sample of the file look like:

     <resources>
        <!-- Default screen margins, per the Android Design guidelines. -->
        <dimen name="activity_horizontal_margin">16dp</dimen>
        <dimen name="activity_vertical_margin">16dp</dimen>
     </resources>
    

    Here activity_veritcal_margin = 16 dp.

    and to use it like this:

    <LinearLayout
        android:id="@+id/activity_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin">
    

    Here we give this linear layout a bottom padding with 16dp.

    0 讨论(0)
提交回复
热议问题