600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > android设置高度比例 android开发layout按比例布局(详解)

android设置高度比例 android开发layout按比例布局(详解)

时间:2023-01-03 14:40:51

相关推荐

android设置高度比例 android开发layout按比例布局(详解)

释放双眼,带上耳机,听听看~!

由于Android的复杂性,在写程序的时候经常会遇见一些难题,也可能会遇见处理不了的问题,下面是技术狗小编详解android layout 按比例布局的代码,一起进入下文了解一下吧!

为了创建比例大小的子View,可以将LinearLayout的宽度和高度设为fill_parent, 而将子View的宽度或是高度设为0,然后为子View设置不同权重(weight) ,这样子View的大小就会权值成比例。

本例使用横向LinearLayout,LinearLayout的android:layout_width=”match_parent”,表示将使用整个屏幕宽度。

对于LinearLayout的几个子View,将它们的宽度都定义为0,android:layout_width=”0dip”,然后使用layout_weight 为每个View指定宽度比例,本例为每个TextView都使用了相同的权值,因此四个TextView将会有相同的宽度。这样对于那些显示文字比较长的TextView的高度就变为多行。

复制代码 代码如下:

android:layout_width=”match_parent”

android:layout_height=”wrap_content”>

android:background=”@drawable/red”

android:layout_width=”0dip”

android:layout_height=”match_parent”

android:layout_weight=”1″

android:text=”@string/linear_layout_7_small”/>

android:background=”@drawable/green”

android:layout_width=”0dip”

android:layout_height=”match_parent”

android:layout_weight=”1″

android:text=”@string/linear_layout_7_big”/>

android:background=”@drawable/blue”

android:layout_width=”0dip”

android:layout_height=”match_parent”

android:layout_weight=”1″

android:text=”@string/linear_layout_7_small” />

android:background=”@drawable/yellow”

android:layout_width=”0dip”

android:layout_height=”wrap_content”

android:layout_weight=”1″

android:text=”@string/linear_layout_7_wrap”/>

以上代码都是技术狗小编详解android layout 按比例布局的代码,希望对大家的学习有一定的帮助!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。