`

Android的Layout及其Param

阅读更多

ViewGroup.MarginLayoutParams

android:layout_marginBottom

android:layout_marginLeft

android:layout_marginRight

android:layout_marginTop

=====================================

ViewGroup.LayoutParams

android:layout_height

android:layout_width

=====================================

FrameLayout.LayoutParams

[ViewGroup.MarginLayoutParams]

[ViewGroup.LayoutParams]

=====================================

AbsoluteLayout.LayoutParams

[ViewGroup.LayoutParams]

layout_x

layout_y

=====================================

LinearLayout.LayoutParams

[ViewGroup.MarginLayoutParams]

[ViewGroup.LayoutParams]

android:layout_gravity

android:layout_weight

=====================================

RelativeLayout.LayoutParams

[android.view.ViewGroup.MarginLayoutParams]

[android.view.ViewGroup.LayoutParams]

android:layout_above

android:layout_alignBaseline

android:layout_alignBottom

android:layout_alignLeft

android:layout_alignParentBottom

android:layout_alignParentLeft

android:layout_alignParentRight

android:layout_alignParentTop

android:layout_alignRight

android:layout_alignTop

android:layout_alignWithParentIfMissing

android:layout_below

android:layout_centerHorizontal

android:layout_centerInParent

android:layout_centerVertical

android:layout_toLeftOf

android:layout_toRightOf

 

 

以上,[...]表示继承关系

 

以上,罗列了各布局下的可用参数。

 

控件的布局不同,体现在xml文件中,其可用的参数(param)也有差异,且其子控件(写在该布局下的控件)。

 

比如,同样是TextView,当布局为LinearLayout时,它的可用的layout参数有9种,而布局为AbsoluteLayout时,它的可用的layout参数只有4种。(当然不同版本的sdk可能会有所差异)。

 

甚至LinearLayout和AbsoluteLayout内幕就没有相同的layout属性。

 

他们之间的比较可以查看附件里的图片,相信大家都会一目了然。

 

布局应用中控件里几乎无处不在,了解什么情况下用什么布局及布局属性,还是很有必要的。

所以,如果在布局不同的情况下,直接进行复制子控件操作很有可能出问题。

分享到:
评论

相关推荐

    谈谈Android里的Context的使用

    android:layout_height="wrap_content" android:text="Welcome to carl shen's blog." /> android:id="@+id/arg_button" android:layout_width="fill_parent" android:layout_height="wrap_content" ...

    Android代码-Immersive

    Immersive 一行代码实现沉浸式,适配android4.4到8.0 ,沉浸式前所未有的简单。 代码示例 public class MainActivity extends AppCompatActivity ... * @param layoutRes 当前activity使用的布局资源Id * @param s

    Android绘制圆环的控件RingPercentView.zip

    绘制圆环的控件,支持时间设置,角度设置,背景设置等一、使用方法1)在Layout中使用如下声明 android:id="@ id/arc_percent"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  app...

    Android代码-NavigationBar

    我的视频课程(基础):《(NDK)FFmpeg打造Android万能音频播放器》 我的视频课程(进阶):《(NDK)FFmpeg打造Android视频播放器》 我的视频课程(编码直播推流):《Android视频编码和直播推流》 标题导航栏,两...

    android地址选择器

    dptProvince.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); //设置适配器 spnProvince.setAdapter(dptProvince); //设置侦听事件 spnProvince.setOnItemSelectedListener...

    Android 判断当前网络是否可用简单实例

    Android 判断当前网络是否可用简单实例 用户手机当前网络可用:WIFI、2G/3G网络,用户打开与不打开网络,和是否可以用是两码事。可以使用指的是:用户打开网络了并且可以连上互联网进行上网... * @param context Contex

    Loadrunner中web_reg_save_param的使用详解

    于是需要首先读出当前的事务的状态,再进行修改,此时便可以使用到web_reg_save_param了。可以通过它先将事务的状态读出写入一个自定义的变量中,根据变量的值来决定下一步的动作。 简要说明 语法:intweb_reg_...

    目录选择器源代码

    -- <TextView android:layout_width="140dip" android:layout_height="35dip" android:id="@+id/dir_str" android:gravity="center" android:layout_weight="1" /> --> android:id="@+id/btn_back" android:...

    Android代码-EasingInterpolator

    EasingInterpolator [![API]...It does not use the standard 4 param ease signature. Instead it uses a single param which indicates the current linear ratio (0 to 1) of the tween.

    高仿微信界面

    android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <include layout="@layout/layout_main_top" /> <android.support.v4.view.ViewPager ...

    nutch-param-set

    nutch-param-setnutch-param-setnutch-param-setnutch-param-set

    Android代码-Low Poly 图片生成器

    > 能够生成low poly风格的图片,Android版本的实现 效果图 使用方法 LowPoly.generate(inputStream,outputStream); 或者 /** * 生成low poly风格的图片 * * @param inputStream 源图片 * @param outputStream ...

    Android代码-灵活的ShadowView,可替代CardView使用

    This library draw android view shadow by ShadowLayer. You may don't like the CardView's black shadow which we can't change it's color. Same to CardView wrap content and set shadow radius. You can ...

    spring配置中<context-param> 和<init-param>的 区别

    &lt;context-param&gt; 和&lt;init-param&gt;的 区别代码 博文链接:https://xhy0422.iteye.com/blog/46319

    Android组件ConverFlow(继承Gallery)

    * This is called during layout when the size of this view has changed. If * you were just added to the view hierarchy, you're called with the old * values of 0. * * @param w * Current width of ...

    Android代码-实现多个TextView流式布局

    a、创建一个Android项目,然后创建一个FlowLayout继承于ViewGroup: public class FlowLayout extends ViewGroup { /** 因为只在代码中直接new,所以创建这个构造方法就可以了 */ public FlowLayout(Context ...

    Android代码-PayPwdEditText

    我的视频课程(基础):《(NDK)FFmpeg打造Android万能音频播放器》 我的视频课程(进阶):《(NDK)FFmpeg打造Android视频播放器》 我的视频课程(编码直播推流):《Android视频编码和直播推流》 支付密码框,和...

    C#语法中的Param应用

    写方法,传参数 Param方法介绍,很贵很有用啊

Global site tag (gtag.js) - Google Analytics