Same layout looks different on a Samsung Galaxy Tab

后端 未结 2 955
-上瘾入骨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:27

    The Problem is following you use in your layout, static values (100dp, 60dp). Now the problem is on a higher resolution this dp isn't the same.

    That means you should create a layout for x-large screens. Also I wouldn't use those static values. Than your application will behave good on many diffrent screensizes!

    Have a great Day

    safari

    0 讨论(0)
  • 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: <dimen name="textview_margin_left">10dp</dimen>,
    in folder values-large: <dimen name="textview_margin_left">20dp</dimen>,
    while in values-xlarge: <dimen name="textview_margin_left">30dp</dimen>

    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.

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