android - 纵向模式和横向模态视图显示调整与手机大小

标签 android layout landscape-portrait

我想根据横向模式纵向模式调整布局。

在我的 7 英寸平板电脑设备中,纵向模式 太小而横向模式 相当大。由于纵向模式较小,列表项和一些文本像按钮一样混合在一起 尺寸变小,一个文本越过另一个文本,等等。

因此对于相同的 View 布局,我想根据模式进行不同的设置。

例如,考虑 One Layout over the Top of Other 的 SO 帖子.我想要这种场景用于肖像模式。但是对于横向模式,我不希望一个 View 重叠在另一个 View 之上。相反,我想要一个 View 在另一侧。

我的不同模式的 xml 布局文件-

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
              android:id="@+id/news_fragment"
              android:layout_weight="1"
              android:layout_width="0dp"              
              android:layout_height="match_parent" />

    <FrameLayout
              android:id="@+id/channel_fragment"
              android:layout_weight="2"
              android:layout_width="0dp"
              android:layout_height="match_parent" />

</LinearLayout>

问题是这对于横向模式来说似乎不错,但是当谈到纵向模式时,我需要news_fragment 来覆盖channel_fragment

考虑到布局文件如何实现此行为是相同的。还是我也必须为肖像创建一个新的?

最佳答案

您只需创建 2 个不同的布局文件。您应该阅读 developer guides关于这个问题。

基本上你制作了 2 个 res/layout 文件夹: res/layoutres/layout-land

然后将横向布局添加到 land 文件夹,将纵向布局添加到另一个文件夹。

关于android - 纵向模式和横向模态视图显示调整与手机大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17081501/

相关文章:

android - 如何在 Android 中创建 HTTP 服务器?

android - 如何使用gradle为味道配置不同的buildType

android - 只重新布局 child 而不是所有的树

findViewById 上的 android ClassCastException

ios - 如何将对象放置在中心图像周围的阵列中?

android - 为 android 手机和平板电脑创建不同的布局

android - 检测 View 在 RecyclerView.ViewHolder 内部分可见

java - Qark 报告 java 文件 : zzaup, zzst、zze、MediaButtonReceiver、TaskStackBuilder 上的 PendingIntent 安全问题

android - PagerSlidingTabStrip 横向模式填充修复

javascript - 识别移动设备的纵向或横向模式和缩放级别(但不特定于浏览器)