精华内容
下载资源
问答
  • wb安卓FrameLayout

    2020-11-04 17:45:28
    FrameLayout 设计FrameLayout是为了显示单一项widget(小部件)。通常,不建议使用FrameLayout显示多项内容,因为他的布局很难调节。不用layout_gravity属性的话,多项内容会重叠,使用layout_gravity的话,能设置...

    FrameLayout

    设计FrameLayout是为了显示单一项widget(小部件)。通常,不建议使用FrameLayout显示多项内容,因为他的布局很难调节。不用layout_gravity属性的话,多项内容会重叠,使用layout_gravity的话,能设置不同的位置。

    layout_gravity:

    top 将对象放在其容器的顶部,不改变其大小
    button 将对象放在其容器的底部,不改变其大小
    left 将对象放在其容器的左侧,不改变其大小
    right 将对象放在其容器的右侧,不改变其大小
    center_vertical 将对象纵向居中,不改变其大小

    注意: 区分“android:gravity”和“android:layout_gravity”:

    android:gravity:是对控件本身来说的,用来设置“控件自身的内容“应该显示在“控件自身体积”的什么位置,默认值是左侧。

    android:layout_gravity:是相对于控件的父元素来说的,设置该控件在它的父元素的什么位置。

    内容大部分来自网络
    自己收集的

    展开全文
  • FrameLayout FrameLayout is the simplest type of layout object. It's basically a blank space on your screen that you can later fill with a single object — for example, a picture that you'll swap...

    FrameLayout

    FrameLayout is the simplest type of layout object. It's basically a blank space on your screen that you can later fill with a single object — for example, a picture that you'll swap in and out. All child elements of the FrameLayout are pinned to the top left corner of the screen; you cannot specify a different location for a child view. Subsequent child views will simply be drawn over previous ones, partially or totally obscuring them (unless the newer object is transparent).



    Linear Layout

    LinearLayout is a ViewGroup that displays child View elements in a linear direction, either vertically or horizontally.

    You should be careful about over-using the LinearLayout. If you begin nesting multiple LinearLayouts, you may want to consider using a RelativeLayout instead.

    1. Start a new project named HelloLinearLayout.
    2. Open the res/layout/main.xml file and insert the following:
      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="vertical"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent">
      
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1">
            <TextView
                android:text="red"
                android:gravity="center_horizontal"
                android:background="#aa0000"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_weight="1"/>
            <TextView
                android:text="green"
                android:gravity="center_horizontal"
                android:background="#00aa00"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_weight="1"/>
            <TextView
                android:text="blue"
                android:gravity="center_horizontal"
                android:background="#0000aa"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_weight="1"/>
            <TextView
                android:text="yellow"
                android:gravity="center_horizontal"
                android:background="#aaaa00"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_weight="1"/>
        </LinearLayout>
              
        <LinearLayout
          android:orientation="vertical"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:layout_weight="1">
          <TextView
              android:text="row one"
              android:textSize="15pt"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_weight="1"/>
          <TextView
              android:text="row two"
              android:textSize="15pt"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_weight="1"/>
          <TextView
              android:text="row three"
              android:textSize="15pt"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_weight="1"/>
          <TextView
              android:text="row four"
              android:textSize="15pt"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_weight="1"/>
        </LinearLayout>
      
      </LinearLayout>

      Carefully inspect this XML. There is a root LinearLayout that defines its orientation to be vertical—all child Views (of which it has two) will be stacked vertically. The first child is another LinearLayoutthat uses a horizontal orientation and the second child is a LinearLayout that uses a vertical orientation. Each of these nested LinearLayouts contain several TextView elements, which are oriented with each other in the manner defined by their parent LinearLayout.

    3. Now open HelloLinearLayout.java and be sure it loads the res/layout/main.xml layout in the onCreate() method:

      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
      }

      The setContentView(int) method loads the layout file for the Activity, specified by the resource ID — R.layout.main refers to the res/layout/main.xml layout file.

    4. Run the application.

    You should see the following:

    Notice how the XML attributes define each View's behavior. Try experimenting with different values for android:layout_weight to see how the screen real estate is distributed based on the weight of each element. See the Common Layout Objects document for more about how LinearLayout handles the android:layout_weight attribute.


    TableLayout

    TableLayout positions its children into rows and columns. TableLayout containers do not display border lines for their rows, columns, or cells. The table will have as many columns as the row with the most cells. A table can leave cells empty, but cells cannot span columns, as they can in HTML.

    TableRow objects are the child views of a TableLayout (each TableRow defines a single row in the table). Each row has zero or more cells, each of which is defined by any kind of other View. So, the cells of a row may be composed of a variety of View objects, like ImageView or TextView objects. A cell may also be a ViewGroup object (for example, you can nest another TableLayout as a cell).

    The following sample layout has two rows and two cells in each. The accompanying screenshot shows the result, with cell borders displayed as dotted lines (added for visual effect).

    <?xml version="1.0" encoding="utf-8"?>
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:stretchColumns="1">
        <TableRow>
            <TextView
                android:text="@string/table_layout_4_open"
                android:padding="3dip" />
            <TextView
                android:text="@string/table_layout_4_open_shortcut"
                android:gravity="right"
                android:padding="3dip" />
        </TableRow>
    
        <TableRow>
            <TextView
                android:text="@string/table_layout_4_save"
                android:padding="3dip" />
            <TextView
                android:text="@string/table_layout_4_save_shortcut"
                android:gravity="right"
                android:padding="3dip" />
        </TableRow>
    </TableLayout>

    Columns can be hidden, marked to stretch and fill the available screen space, or can be marked as shrinkable to force the column to shrink until the table fits the screen. See the TableLayout reference documentation for more details.

    To view sample code, see the Hello TableLayout tutorial.


    RelativeLayout

    RelativeLayout lets child views specify their position relative to the parent view or to each other (specified by ID). So you can align two elements by right border, or make one below another, centered in the screen, centered left, and so on. Elements are rendered in the order given, so if the first element is centered in the screen, other elements aligning themselves to that element will be aligned relative to screen center. Also, because of this ordering, if using XML to specify this layout, the element that you will reference (in order to position other view objects) must be listed in the XML file before you refer to it from the other views via its reference ID.

    The example below shows an XML file and the resulting screen in the UI. Note that the attributes that refer to relative elements (e.g., layout_toLeft) refer to the ID using the syntax of a relative resource (@id/id).

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android
                    android:layout_width="fill_parent" 
                    android:layout_height="wrap_content"
                    android:background="@drawable/blue"
                    android:padding="10px" >
    
        <TextView android:id="@+id/label" 
                  android:layout_width="fill_parent" 
                  android:layout_height="wrap_content" 
                  android:text="Type here:" />
    
        <EditText android:id="@+id/entry" 
                  android:layout_width="fill_parent" 
                  android:layout_height="wrap_content" 
                  android:background="@android:drawable/editbox_background"
                  android:layout_below="@id/label" />
      
        <Button android:id="@+id/ok" 
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content" 
                android:layout_below="@id/entry"
                android:layout_alignParentRight="true"
                android:layout_marginLeft="10px"
                android:text="OK" />
    
        <Button android:layout_width="wrap_content" 
                android:layout_height="wrap_content"
                android:layout_toLeftOf="@id/ok"
                android:layout_alignTop="@id/ok"
                android:text="Cancel" />
    </RelativeLayout>

    Some of these properties are supported directly by the element, and some are supported by its LayoutParams member (subclass RelativeLayout for all the elements in this screen, because all elements are children of a RelativeLayout parent object). The defined RelativeLayout parameters are: widthheightbelowalignToptoLeftpadding[Bottom|Left|Right|Top], andmargin[Bottom|Left|Right|Top]. Note that some of these parameters specifically support relative layout positions — their values must be the ID of the element to which you'd like this view laid relative. For example, assigning the parameter toLeft="my_button" to a TextView would place the TextView to the left of the View with the ID my_button (which must be written in the XML beforethe TextView).

    To view this sample code, see the Hello RelativeLayout tutorial.




    展开全文
  • 安卓——FrameLayout

    2018-02-26 14:26:06
    上图的xml&lt;...FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="



    上图的xml

    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.example.lenovo.relativelayout.MainActivity">
    
    
        <TextView
            android:layout_gravity="center"
            android:background="#987645"
            android:id="@+id/textView1"
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:text="第一个页面" />
        <TextView
            android:layout_gravity="center"
            android:background="#447645"
            android:id="@+id/textView2"
            android:layout_width="150dp"
            android:layout_height="150dp"
            android:text="第二个页面" />
        <TextView
            android:layout_gravity="center"
            android:background="#337645"
            android:id="@+id/textView3"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:text="第三个页面" />
        <TextView
            android:layout_gravity="center"
            android:background="#667645"
            android:id="@+id/textView4"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:text="第四个页面" />
    </FrameLayout>
    
    
    



    上图的xml

    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.example.lenovo.relativelayout.MainActivity">
    
    
        <ProgressBar
            android:id="@+id/progressBar"
            style="?android:attr/progressBarStyle"
            android:layout_width="101dp"
            android:layout_height="96dp"
            android:layout_gravity="center" />
    
        <TextView
            android:layout_gravity="center"
            android:id="@+id/textView5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="60%" />
    </FrameLayout>
    

    展开全文
  • 安卓布局之framelayout

    2020-04-26 14:47:17
    Framelayout布局: frameLayout为框架布局,该布局的特点为层层覆盖,即最先放置的部件位于最下层,最后放置的部件位于最上层。 xml代码: <FrameLayout xmlns:android=...

    Framelayout布局:
    frameLayout为框架布局,该布局的特点为层层覆盖,即最先放置的部件位于最下层,最后放置的部件位于最上层。

    xml代码:

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <TextView
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:background="@color/colorPrimaryDark"
            android:layout_gravity="center"/>
    
        <TextView
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:background="@color/colorPrimary"
            android:layout_gravity="center"/>
    
        <TextView
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:background="@color/colorAccent"
            android:layout_gravity="center"/>
    
    </FrameLayout>
    

    效果图:
    在这里插入图片描述

    展开全文
  • 安卓学习之FrameLayout

    2016-09-04 21:15:00
    将《第一行代码》中的代码输入,并不能得到书上的结果,按钮无论如何都是在图片上面,后来找到http://www.cnblogs.com/DarkMaster/p/4654953.html,将button空间外面包一层 <RelativeLayout6 android:layout_...
  • 安卓开发24:FrameLayout布局

    千次阅读 2013-08-23 14:32:37
    FrameLayout布局 FrameLayout是五大布局中最简单的一个布局。FrameLayout布局中的元素会根据先后顺序重叠起来。利用FrameLayout布局元素重叠的特性,我们一般可以做一些层的隐藏和显示,以及在一个图片上放置另外一...
  • 概述: 最简单的布局形式 ,组件都放在屏幕的左上角,组件是按次序加入次序层叠在一起,上一层的控件会覆盖下一层的控件 属性和方法: XML属性 值设置对象边缘与父布局的边缘之间...android:padding
  • 关注 安卓007 ,免费获取全套安卓开发学习资料 什么是FrameLayout FrameLayout又称帧布局,开发中很少使用,因其定位方式过于简单,所有控件都默认定位左上角.也支持将子控件显示在父控件的上下左右及正中间. 基础样例 1...
  • 知识共享,封装framelayout通过意图转换知识
  • 一直想研究下安卓各种布局控件,FrameLayout安卓最简单的界面布局,所以就从FrameLayout讲起。 1.属性。frameLayout继承ViewGroup,除了拥有ViewGroup的属性之外,只有一个layout_gravity属性。看它的内部静态类...
  • 安卓开发学习之FrameLayout的layout过程

    千次阅读 2018-05-14 22:08:49
    背景前段时间我阅读了三大常用布局FrameLayout、RelativeLayout、LinearLayout的测量过程,众所周知,view的绘制过程有三大步:测量、布局、绘制,所以做事有始亦有终,我开始了阅读三大布局的layout过程,主要是...
  • 背景前两天我分别阅读了下相对布局和线性布局的测量流程的源代码,今天,我就安卓开发中的框架布局(FrameLayout)的测量流程源码的阅读,进行一些记录分步骤框架布局的onMeasure()相比相对布局和线性布局的要简单的多...
  • 主要运用radiogroup和framelayout结合实习简单的tab切换;首先在drawable下创建selector_radiogroup.xml和shape_radiogroup.xml&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;...
  • 安卓布局 - 帧布局(FrameLayout)

    千次阅读 2017-02-07 20:53:17
    FrameLayout (帧布局),在实际开发中用的较少,只有在特定的场合才需要。 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:l
  • 宽高不必说,x/y使用leftMargin/rightMargin来实现。
  • 视频下载: http://pan.baidu.com/s/1gd1eQbD 完整代码及实验说明 请参考教材: ... 本节内容: //在xml中使用FrameLayout 帧布局实现颜色的渐变
  • FrameLayout直接继承了ViewGroup,常用的XML属性 属性 方法 说明 android:foreground setForeground(Drawable drawable) 设置前景图像 android:foregroundGravity setForegroundGravity(int ...
  • 1、fill_parent和match_parent,在android2.2中,fill_parent无效。 2、框架布局是最简单的布局方式,所有添加到这个布局中的视图都是以层叠的方式显示。第一个添加到框架布局中的视图显示...</FrameLayout>
  • 一.FrameLayout介绍: FrameLayout是五大布局中最简单的一个布局,在这个布局中,整个界面被当成一块空白备用区域,所有的子元素都不能被指定放置的位置,它们统统放于这块区域的左上角,并且后面的子元素直接覆盖...
  • 1.FrameLayout(框架布局)框架布局又叫帧布局是android六大布局中最为简单的布局之一,该布局直接在屏幕上开辟出了一块空白区域,。所有添加到这个布局中的视图都以层叠的方式显示,所有的组件默认都会放置于这块区域的...
  • 帧布局的机制 从左上角开始绘制。 若有重叠,会按照顺序,把前一个的覆盖(前景也会有此机制): 前景的设置:foreground、foregroundGravity
  • layout也可以include不听说过没呢 include就是将某个写好的layout添加到另一个layout里 include好处有: 减少在主布局文件中的代码量,看起来更加清晰。 把各部分独立开来,方便管理。 可以多处复用 ...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 395
精华内容 158
关键字:

安卓framelayout