对自己现在所了解的layout_weight属性进行记录,不求全面,只求正确!
layout_weight意为"权重",我的理解就是给组件设置一个显示大小的比例。
layout_weight设置一个值,会出现两种情况。
第一种:当组件的“layout_width”属性为“fill_parent”时,值越小,组件越大。
第二种:当组件的“layout_width”属性为“wrap_content”时,值越大,组件越大。
第一种情况:
<LinearLayout
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
>
<Button
android:id="@+id/btn_save"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="保存"
/>
<Button
android:id="@+id/btn_return"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="4"
android:text="返回"
/>
</LinearLayout>
在这里"保存"按钮的Layout_weight=1,"返回"按钮的Layout_weight=4,layout_width="fill_parent"时, 运行效果为:
第二种情况:
<LinearLayout
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
>
<Button
android:id="@+id/btn_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="保存"
/>
<Button
android:id="@+id/btn_return"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="4"
android:text="返回"
/>
</LinearLayout>
在这里"保存"按钮的Layout_weight=1,"返回"按钮的Layout_weight=4,layout_width="wrap_content"时,运行效果为:
以上为本人对已知情况的总结,如有不对或总结不足,望指教!
- 大小: 2.5 KB
- 大小: 2.8 KB
分享到:
相关推荐
主要介绍了Android应用中通过Layout_weight属性用ListView实现表格的方法,文中对Layout_weight属性先有一个较为详细的解释,需要的朋友可以参考下
Android支持多屏幕机制即用为当前设备屏幕提供一种合适的方式来共同管理并解析应用资源。本文就介绍了4中Android屏幕自适应解决方案。...传统的layout_weight使用方法是将当前控件的layout_width和layout_
查了下资料,说是要设置layout_weight属性 资料说得不是很清楚,也没仔细看,就去弄,结果越弄越混乱。 于是静下心来,自己写xml测试,发现如下。 如果LinearLayout是最外面的一层,它是不会弹出layout_weight属性的...
android:layout_weight="1" android:layout_height="wrap_content" android:text="行1列2" /> <TextView android:layout_width="wrap_content" android:layout_weight="1" android:layout_height="wrap_content...
对android布局中的layout_weight属性进行深入讲解。
如果您想定义高度屏幕为percetange,可将其设置为match_parent,滑动视图定义为layout_weight属性。 默认情况下,整个面板将作为拖动区域和将截获的点击和拖动事件。可以通过使用setDragView方法或...
<Button android:id="@+id/example_row_b_action_2" android:layout_width="0dp" android:layout_height="60dp" android:layout_gravity="center" android:layout_marginLeft="10dp" android:layout_weight="1" ...
android:layout_weight="1" app:emptyView="@layout/empty_view" > 你的原有的内容布局 </com.xiaomagouche.loadinglayout.library.LoadingLayout>2. 控制状态变化LoadingLayout loadingLayout = ...
android:layout_weight="1"> <android.support.v4.view.ViewPager android:id="@ id/viewpager_default" android:layout_width="match_parent" android:layout_height="match_parent"/> ...
android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent"/> android:onClick="scrollTo3" android:background="@android:color/holo_green_light" android:...
但是当我们要是图标跟着文字后面,第一时间想到用LinearLayout的layout_weight 来做,但是做出来效果不一样。 后来竟然忘记这个属性了:指定TextView的最大宽度实现自动省略 android:maxWidth=90dp ,加上
增加阴影效果,让控件或者布局看起来有立体的效果,总的来说有两种解决方案。 1,直接使用属性: android:elevation=”4dp”这样一句代码,就实现了... android:layout_weight=1 android:gravity=center android:e
android:layout_weight="1"//权重,控制控件之间的地位,在控制控件显示的大小时蛮有用的。 android:textAppearance="?android:attr/textAppearanceLargeInverse"//文字外观 android:layout_gravity="center_vertical...
Android 自定义选择列表示例 此示例演示了如何创建自定义可检查布局,以与 ListView 的 choiceMode 属性一起使用。 介绍 此示例演示了如何在 Android ... android : layout_weight = " 1 " android : paddingLeft =
1、selector的使用 2、style的使用 3、将一个TextView放在一个EditText中(使用相对布局…… ...6、是两个控件在同一行平均分布(这两个控件放在一个LinearLayout中,分别设置2控件的属性android:layout_weight="1
android:layout_weight="1" android:layout_height="wrap_content" android:layout_marginLeft="15dp" android:layout_marginTop="5dp" android:layout_marginBottom="5dp" android:layout_marginRight="10dp...
android:layout_weight—– 给控件分配剩余空间 先给大家展示一下导图: 知识点详解(演示效果方便组件没有设置id) (1)gravity和Layout_gravity android:gravity 属性是对该view中内容的限定.比如一个...