温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

【学习笔记】Android常用布局

发布时间:2020-07-23 18:48:37 来源:网络 阅读:332 作者:wx57a1620925627 栏目:移动开发


一、LinearLayout线性布局

(1)线性布局分为垂直和水平两个方向

     android:orientation="vertical"
     android:orientation="horizontal"

(2)定义宽和高

     铺满父级容器:match_parent
     根据内容自适应:wrap_content
     android:layout_width=""
     android:layout_height=""

(3)设置权重

      android:layout_weight="1"  全部

二、RelativityLayout相对布局

   

    //新建并设置一个RelativityLayout布局

     RelativityLayout root=new RelativityLayout(this);

    setContentView(root);

    

    //添加一个textView控件

     TextView tv=new TextView(this);

    tv.setText("hello");

    

    //定义RelativityLayout参数,有两个参数高和宽

    RelativityLayout.LayoutParams lp=new RelativityLayout.LayoutParams(RelativityLayout.LayoutParams.WrapContent,RelativityLayout.LayoutParams.WrapContent);

    root.addView(tv,lp);


三、 FrameLayout


用的比较少,加进来的控件自动堆叠在一起。日后再补充

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI