【问题标题】:Need a working Example of Handling large and small screens on Android需要一个在 Android 上处理大屏幕和小屏幕的工作示例
【发布时间】:2017-05-11 09:17:52
【问题描述】:

我尝试了很多方法来处理 Android 上的多个平板电脑和手机屏幕,但无法找到正确的方法。在某些情况下,我会遇到错误,而有些则不起作用。我也发布了Stack Question,但没有收到满意的结果。 我想在平板电脑屏幕上并排显示列表和说明,而仅在移动屏幕上显示。有什么好的和简单的方法可以做到这一点吗?我也试过this,但没能达到目的。

【问题讨论】:

  • 您是否尝试过使用多窗格片段
  • @poojarc 是的,我试过了。请参阅相关堆栈链接。

标签: android android-fragments android-tablet-layout


【解决方案1】:

使用 xhdpi 资源,并尝试根据设备使用布局参数在运行时设置所有布局。

或者让 android 决定什么最适合设备创建以下文件夹

layout-large
layout-small
layout-sw600
layout-sw720

和类似的文件夹可以更好地组织您的布局

【讨论】:

    【解决方案2】:

    是的,您可以这样做。有一种方法可以让您根据设备选择布局。

    res/layout/my_layout.xml              // layout for normal screen size ("default")
    res/layout-large/my_layout.xml        // layout for large screen size
    res/layout-xlarge/my_layout.xml       // layout for extra-large screen size
    res/layout-xlarge-land/my_layout.xml  // layout for extra-large in landscape orientation
    
    res/drawable-mdpi/graphic.png         // bitmap for medium-density
    res/drawable-hdpi/graphic.png         // bitmap for high-density
    res/drawable-xhdpi/graphic.png        // bitmap for extra-high-density
    res/drawable-xxhdpi/graphic.png       // bitmap for extra-extra-high-density
    
    res/mipmap-mdpi/my_icon.png         // launcher icon for medium-density
    res/mipmap-hdpi/my_icon.png         // launcher icon for high-density
    res/mipmap-xhdpi/my_icon.png        // launcher icon for extra-high-density
    res/mipmap-xxhdpi/my_icon.png       // launcher icon for extra-extra-high-density
    res/mipmap-xxxhdpi/my_icon.png      // launcher icon for extra-extra-extra-high-density
    

    如果是 10' 选项卡,则在

    中创建布局
    res/layout-sw720dp/my_layout.xml
    

    如果是 7' 选项卡,则在

    中创建布局
    res/layout-sw600dp/my_layout.xml
    
    
     <?xml version="1.0" encoding="utf-8"?>
    

    <TextView
        android:id="@+id/title_detailfragment"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/detail_fragment"/>
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">
        <fragment
            android:name="com.example.fyp_awais.tab.MainActivity$MyListFragment"
            android:id="@+id/list_fragment"
            android:layout_height="match_parent"
            android:layout_width="0dp"
            android:layout_weight="1" />
        <fragment
            android:name="com.example.fyp_awais.tab.MainActivity$MyDetailFragment"
            android:id="@+id/detail_fragment"
            android:layout_height="match_parent"
            android:layout_width="0dp"
            android:layout_weight="1" />
    
    </LinearLayout>
    

    【讨论】:

    • 是的,我知道这一点。但是如何在平板布局中并排显示两个片段呢?我已经在问题中提到了这一点。也可以看看我的问题http://stackoverflow.com/questions/41330315/binary-xml-file-line-20-error-inflating-class-fragment-android
    • 取一个LinearLayout,然后取两个RelativeLayout,并为它们分配宽度权重。
    • 现在使用这个RelativeLayouts来展示你的片段
    • 如果您向我推荐工作示例。我会非常感谢你。
    猜你喜欢
    • 2013-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多