0
0

【Android】レイアウトを比率で大きさを指定する

Posted at

はじめに

今回は XML内で面白いものはないかと遊んでいた所見つけた 比率で大きさ指定をする方法を記事に残しておきます。

実践

widthのサイズを基準にheightのサイズに合わせるか、逆にheightのサイズを基準にwidthのサイズに合わせるかを指定でき、widthのw か heightのhで指定する その後ろに,で区切り比率を数字で指定する。

android:layout_width="100dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="h,1:1"

上の例では widthをheightに合わせて1:1にするのでどちらも100dpになる。

注意としてConstraintsLayout内でしか使えないということがあげられます。

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