简体   繁体   English

在布局方面支持不同的屏幕尺寸和密度

[英]Supporting different screen sizes and densities in regards to layout

I would like to know how to make my app support different screen sizes and densities, including tablets, regarding the layout. 我想知道如何让我的应用程序支持有关布局的不同屏幕尺寸和密度,包括平板电脑。 I've found different answers on SO, but I can't find one that explains this issue the best. 我在SO上找到了不同的答案,但是找不到能最好地解释该问题的答案。

I've already included this in my Manifest: 我已经将其包含在清单中:

<supports-screens
    android:anyDensity="true"
    android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:xlargeScreens="true" />

According to this answer, I should create multiple layout folders such as small, large, xlarge. 根据答案,我应该创建多个布局文件夹,例如small,large,xlarge。

According to documentation I should create multiple layouts and use size qualifiers such as sw<N>dp . 根据文档,我应该创建多个布局并使用大小限定符,例如sw<N>dp

Which would be the best solution if my app needs to support both phones and tablts? 如果我的应用程序需要同时支持电话和Tablt,哪种方法是最好的解决方案?

Additional question: In connection with the abovementioned question, I have a recycler view with list of items. 附加问题:关于上述问题,我有一个带有物品清单的回收站视图。 If the screen is portrait then there's a list, if the screen is landscape, then there's grid. 如果屏幕是纵向屏幕,则有一个列表;如果屏幕是横向屏幕,则有网格。

if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
        LinearLayoutManager manager = new LinearLayoutManager(getContext());
        mBinder.rvHistoryList.setLayoutManager(manager);
    } else if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
        GridLayoutManager manager = new GridLayoutManager(getContext(), 2);
        mBinder.rvHistoryList.setLayoutManager(manager);
    }

But, if the app is used on a tablet in portrait mode I would like the items to be in a grid ordered by 2 in a row, if the app is used on a tablet in landscape mode I would like the items to be in a grid ordered by 4 in a row. 但是,如果该应用程序在平板电脑上以纵向模式使用,我希望这些项目以连续2的顺序排列在网格中;如果该应用程序在平板电脑上以横向模式使用,我希望这些项目位于一个网格连续按4排序。 How can I achieve this? 我该如何实现?

Creating few layouts for different size is old and confusing method. 创建几个不同大小的布局是一种古老而令人困惑的方法。
You can set weight for each layout and component. 您可以为每个布局和组件设置权重。

This is good tutorial for beginning. 这是一个很好的入门教程。

http://www.101apps.co.za/index.php/articles/using-android-s-layout-weight-attribute.html http://www.101apps.co.za/index.php/articles/using-android-s-layout-weight-attribute.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM