Same layout looks different on a Samsung Galaxy Tab

后端 未结 2 956
-上瘾入骨i
-上瘾入骨i 2021-01-27 02:58

I\'m developing an Android 2.2.2 application which will support multiple screens sizes and all screens will be portrait. I won\'t support landscape.

I have test the foll

2条回答
  •  再見小時候
    2021-01-27 03:34

    Indeed, the advice you received was good: it's possible to have only one layout file, but as it was already suggested in comments, it's not good to hardcode dimensions, even if you use dp or dip, specially when you are targeting all the screen sizes and densities available.

    Instead, you should replace those values with links to dimensions values.

    For example, instead of android:layout_marginLeft="10dp", you'll have something like

    android:layout_marginLeft="@dimen/textview_margin_left"
    

    where textview_margin_left is defined in the dimens.xml, having different values in different folders;
    probably in folder values: 10dp,
    in folder values-large: 20dp,
    while in values-xlarge: 30dp

    But this is just an example, you have to test on all dimensions and resolutions and find the best values for your layout. In Eclipse, in Graphical Layout mode, you can easily get an idea about how your layout looks on various devices, just by clicking on Nexus One, and choosing another model from the list, and the layout will automatically update.

    Also, you can move in dimens.xml all the text sizes, and that will be very useful for x-large devices.

    Using only one RelativeLayout instead many imbricated LinearLayouts might also be a good idea, and using relative positioning for your objects, instead some of the hardcoded values.

提交回复
热议问题