RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
android:weight的使用

android:weight属性能够根据手机高宽按设定比例显示控件

创新互联建站专注于建安企业网站建设,响应式网站开发,商城系统网站开发。建安网站建设公司,为建安等地区提供建站服务。全流程按需定制开发,专业设计,全程项目跟踪,创新互联建站专业和态度为您提供的服务

如:

宽度上按比例显示

                android:layout_marginTop="5dp"
                androidandroid:weight的使用rientation="horizontal"
                android:layout_width="fill_parent"----------------让其满宽
                android:layout_height="wrap_content">
                                android:id="@+id/first_sex1_4"
                    android:layout_marginLeft="15dp"
                    android:layout_width="0dp"---------设置0dp,让宽度由比例生成
                    android:layout_weight="1"
                    android:layout_height="50dp"/>
                                android:id="@+id/first_sex1_5"
                    android:layout_marginLeft="5dp"
                   android:layout_width="0dp"
                    android:layout_weight="3"
                    android:layout_height="50dp"/>         
        

注意现在android:layout_width="0dp"

最终3个按钮显示的宽度比例为1:3,和weight一样,值大的权高,显示宽度大


然而如果把 android:layout_width="fill_parent"

                android:layout_marginTop="5dp"
                androidandroid:weight的使用rientation="horizontal"
                android:layout_width="fill_parent"----------------让其满宽
                android:layout_height="wrap_content">
                                android:id="@+id/first_sex1_4"
                    android:layout_marginLeft="15dp"
                    android:layout_width="fill_parent"---------设置fill_parent,让宽度由比例生成
                    android:layout_weight="1"
                    android:layout_height="50dp"/>
                                android:id="@+id/first_sex1_5"
                    android:layout_marginLeft="5dp"
                   android:layout_width="fill_parent"
                    android:layout_weight="3"
                    android:layout_height="50dp"/>         
        

注意现在android:layout_width="fill_parent"

最终3个按钮显示的宽度比例为3:1,和weight相反,值大的权低,显示宽度小


当前文章:android:weight的使用
文章起源:http://sczitong.cn/article/jocjpj.html