LinearLayout水平超出小屏幕

时间:2013-06-28 14:04:21

标签: android width screen android-linearlayout

我有两个DatePickers,并排。 它在较大的屏幕上运行良好,但是当我在较小的设备上运行我的应用程序时,我只看到第一个,另一个被截断。

当屏幕上没有足够的空间时,我希望第二个DatePicker被淹没在第一个的底部。

是否有可能以编程方式避免在XML文件中执行此操作?

这是我的代码片段。它嵌套在另一个LinearLayout中。

<LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal" >

        <DatePicker
            android:id="@+id/date_start"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:calendarViewShown="false" />

        <DatePicker
            android:id="@+id/date_end"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:calendarViewShown="false" />
    </LinearLayout>

2 个答案:

答案 0 :(得分:0)

你可以使用FlowLayout,它不是默认的sdk,但有人已经开发了它,看看: https://github.com/ApmeM/android-flowlayout

答案 1 :(得分:0)

您可以在layout-large中创建文件夹res并将此代码移到那里。然后,您可以在较小的屏幕上更改此代码。在较大的屏幕上,您的应用将使用layout-large并在较小的屏幕上使用layout文件夹

您只需更改此代码即可使用orientation vertical,也可以调整其他一些属性,具体取决于它在较小屏幕上的外观。

Using Layout qualifiers

仅仅是一个FYI,LinearLayout默认orientation horizontal,因此不需要属性,但也不会受到伤害。我只想指出这一点,因为将来可能会有所帮助。

相关问题