开发者

How do I stretch a UI Element to fill the vertical space on a view?

I have a layout that contains three rows or segments in my Android view.

The first layout region has a fixed height based upon the content of the region with a:layout_height="wrap_content".

The next segment will contain a ListView with it's built in scrolling capability, I would like this to take up the available screen real-estate.

The final segment will always have a fixed height based upon an absolute value or a:layout_height="32dp". I would like this thrid segment "docked" to the bottom of the view.

For reference the following XAML accomplishes what I want

<Grid>
   <Grid.RowDefinitions>
       <RowDefinition Height="auto" />
       <RowDefinition Height="*" />
       <RowDefinition Height="32" />
   </Grid.RowDefinisi开发者_JAVA技巧ons>
</Grid>

Is this possible via android layout XML? And if so how can this be done.


Set android:layout_height="fill_parent", android:layout_height="match_parent" or android:layout_weight="1".

The latter will take all of the remaining unused space in its parent layout, the former will sometimes force other elements out of view.


This is definitely possible. You can do this many ways, the easiest of which in my opinion is to simply use a LinearLayout. Something like:

<LinearLayout layout_height="fill_parent">
    <firstitem layout_height="wrap_content" layout_width="fill_parent" />
    <ListView layout_height="fill_parent" layout_width="fill_parent" />
    <bottomitem layout_height="32dp" layout_width="fill_parent" />
</LinearLayout>

Use dp not sp. sp is generally for font sizes, dp for everything else.

By the way, here's a good guide to get you started with common layout objects.


Have you tried layout_width="fill_parent"?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜