如何在横向布局中包含纵向布局?

时间:2016-03-28 15:45:44

标签: android layout landscape

我设计了完美的人像布局。我想将其作为横向版本的一部分(见附件)。

Layout for Landscape version

没有额外的功能,所以我认为不需要麻烦使用碎片。

当然,不能在横向版本中包含版面的纵向版本。下面的代码产生了明显的错误:“布局不应该包含自身”:

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

    <include
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        layout="@layout/my_perfect_layout"
        />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:src="@drawable/demo"
        />
</LinearLayout>

有没有办法强制布局目录,以便我不会得到这包括无限循环?或者还有另一种方式吗?我真的想避免在此时更改任何java代码!

1 个答案:

答案 0 :(得分:1)

最佳实践:

  • 将您的内容布局放入无方向的布局文件中。 (这是可重复使用的部分)
  • 为您要使用的所有方向创建一个框架布局文件,并包含内容布局。 (这是您放置特定于布局的部分的部分,例如在景观中包含更多内容)
相关问题