问题
I have two DatePickers, side by side. It works good on larger screen, but when I run my application on smaller devices, I only see the first one, the other is truncated.
I'd like the second DatePicker being drown at the bottom of the first one when there's no enough space on the screen.
Is it possible avoiding programmatically ways and do it in the XML file?
This is the fragment of my code. It's nested in another 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>
回答1:
You can create a folder layout-large
in res
and move this code there. Then you can change this code to be how you want on a smaller screen. When on larger screens your app will use the layout-large
and use the layout
folder when on smaller screens
You would simply need to change this code to use an orientation
of vertical
and maybe adjust some other properties depending on how it will look on smaller screens.
Using Layout qualifiers
Just an FYI, LinearLayout
has an orientation
of horizontal
by default so that property isn't needed but doesn't hurt, either. I just like to point that out because it may be useful to know in the future.
回答2:
You can use a FlowLayout, it is not a sdk default, but someone already developed it, take a look: https://github.com/ApmeM/android-flowlayout
来源:https://stackoverflow.com/questions/17366549/linearlayout-horizontal-exceeds-small-screen