LoginSignup
0
0

More than 1 year has passed since last update.

TableViewの下のViewの高さが確保できない場合の対処

Posted at

この度、個人ブログを閉鎖することなり、一定のアクセスがあった記事を記録として遺すことにしました。
以下は、2018年7月15日に投稿した記事の写しです。この記事がこの世の誰かの助けとなることを願います。

iOSでTableViewとかListViewの様なスクロールできるViewの下にContentViewを設置するとHeigthRequestで指定した高さを確保できない場合があります。

例えば、TableViewの下に高さ50のContentVIewを設置する以下の様なXAMLを書いてみます。

<StackLayout Spacing="0">
    <TableView Intent="Settings">
        <TableSection Title="TableSection">
            <TextCell BindingContext="{x:Reference bottom}" Text="HeightRequest" Detail="{Binding HeightRequest}"/>
            <TextCell BindingContext="{x:Reference bottom}" Text="Height" Detail="{Binding Height}"/>
        </TableSection>
    </TableView>
    <ContentView x:Name="bottom" HeightRequest="50" BackgroundColor="Lime" />
</StackLayout>

実行結果は以下の通りです。
20180715172757.png
出典元は忘れてしまったので、なぜこうすべきかなどの説明はできませんが
TableView要素にRowHeight="-1" HeightRequest="-2"を追記することで解決します。

<StackLayout Spacing="0">
    <TableView Intent="Settings" RowHeight="-1" HeightRequest="-2">
        <TableSection Title="TableSection">
            <TextCell BindingContext="{x:Reference bottom}" Text="HeightRequest" Detail="{Binding HeightRequest}"/>
            <TextCell BindingContext="{x:Reference bottom}" Text="Height" Detail="{Binding Height}"/>
        </TableSection>
    </TableView>
    <ContentView x:Name="bottom" HeightRequest="50" BackgroundColor="Lime" />
</StackLayout>

20180715173338.png
正直、一見しても良くわからないくらいの差なのですが、画面下にAdmobのバナーを設置したい場合などは、広告のフォーマットが変わったりするので注意が必要かと思います。
20180715174059.png 20180715174102.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0