zoukankan      html  css  js  c++  java
  • 什么是布局?Android中的布局是怎样的?

    布局管理器(通常被称为是布局)是对ViewGroup类的扩展,是用来控制子控件在UI中的位置。

    Android SDK包含了许多布局类,在为视图、Fragment和Activity创建UI时,可以使用和修改这些类,还可以创建自己的布局类。

    其实说白了,布局管理器或布局就是Layout的一种。

    Android SDK提供一些常用的布局类:FrameLayout、LinearLayout、RelativeLayout和GridLayout。

    一般实现布局,是使用XML文件的形式定义的。在XML中实现布局可以把表示层从视图、Fragment和Activity代码中分离出来。也可以创建支持特定硬件的、无需修改代码就可以动态加载的变体。

    如果情况需要,也可以使用代码实现布局。比如下述情况实现:

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            LogUtil.d(TAG, "onCreate..");
            LinearLayout ll = new LinearLayout(this);
            ll.setOrientation(LinearLayout.VERTICAL);
            TextView textView = new TextView(this);
            textView.setText("Enter Text Below");
            EditText editText = new EditText(this);
            editText.setText("Text Goes Here!");
            int lWidth = LinearLayout.LayoutParams.MATCH_PARENT;
            int lHeight = LinearLayout.LayoutParams.WRAP_CONTENT;
            ll.addView(textView, new LinearLayout.LayoutParams(lWidth, lHeight));
            ll.addView(editText, new LinearLayout.LayoutParams(lWidth, lHeight));
            setContentView(ll);
        }

    实现的布局如下:

  • 相关阅读:
    590. N-ary Tree Postorder Traversal
    700. Search in a Binary Search Tree
    885. Spiral Matrix III
    876. Middle of the Linked List
    908. Smallest Range I
    java中Class对象详解和类名.class, class.forName(), getClass()区别
    应用层之web和http
    122. 买卖股票的最佳时机 II
    129. 求根到叶子节点数字之和
    849. 到最近的人的最大距离
  • 原文地址:https://www.cnblogs.com/CVstyle/p/6399231.html
Copyright © 2011-2022 走看看