我想根据横向模式
和纵向模式
调整布局。
在我的 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/layout
和
res/layout-land
然后将横向布局添加到 land
文件夹,将纵向布局添加到另一个文件夹。
关于android - 纵向模式和横向模态视图显示调整与手机大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17081501/