zoukankan      html  css  js  c++  java
  • RelativeLayout总结

    RelativeLayout关系布局:

     

    在form中的用法:"@[+][package:]type:name"   (@id/viewName)

    在主题模式form中的用法: "?[package:][type:]name".(还没见过相关的例子)

     

    android:layout_above VS android:layout_below:

    设定当前view和相关的view在垂直方向上的关系,above是上相关view的上面,below是在相关view的下面,above让当前view的下面界和相关view的上边界对齐。相反below则是将当前view和相关view的上边界对齐。

    在form中的用法:"@[+][package:]type:name"   (@id/viewName)

    在主题模式form中的用法: "?[package:][type:]name".(还没见过相关的例子)

     

    android:layout_alignBaseline

    大概相当于水平中心线对齐。

    android:layout_alignBottom

    android:layout_alignLeft

    android:layout_alignRight

    android:layout_alignTop

    以上这些同理。

     

    android:layout_alignParentBottom

    android:layout_alignParentLeft

    android:layout_alignParentRight

    android:layout_alignParentTop

    android:layout_centerHorizontal

    android:layout_centerInParentc

    android:layout_centerVertical

    以上四项是指在父容器中的位置。

     

    android:layout_alignWithParentIfMissing

    If set to true, the parent will be used as the anchor when the anchorcannot be be found for layout_toLeftOf, layout_toRightOf, etc.

    如果设为true,当找不到toLeftOf或toRightOf的view的时候,父容器将成为锚点,以父容器做为布局的依据。

     
    代码


    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:orientation
    ="vertical" android:layout_width="fill_parent"

    android:layout_height
    ="fill_parent">

    <TextView android:id="@+id/label" android:layout_width="fill_parent"

    android:layout_height
    ="wrap_content" android:text="Type here:" />

    <EditText android:id="@+id/txt" android:layout_width="match_parent"

    android:layout_height
    ="wrap_content"

    android:background
    ="#ffffff"

    android:layout_below
    ="@id/label"

    />

    <Button android:id="@+id/btnOk"

    android:layout_width
    ="wrap_content"

    android:layout_height
    ="wrap_content"

    android:layout_below
    ="@id/txt"

    android:layout_alignParentRight
    ="true"

    android:layout_marginLeft
    ="10dip"

    android:text
    ="√"/>

    <Button android:id="@+id/btnCancel"

    android:layout_width
    ="wrap_content"

    android:layout_height
    ="wrap_content"

    android:layout_alignParentBottom
    ="true"

    android:layout_alignParentLeft
    ="true"

    android:layout_alignBaseline
    ="@id/btnOk"

    android:layout_toLeftOf
    ="@id/btnOk"

    android:layout_alignWithParentIfMissing
    ="true"

    android:text
    ="X"/>
    </RelativeLayout>

            super.onCreate(savedInstanceState);
    
            setContentView(R.layout.main);
    
            Button btn = (Button)findViewById(R.id.btnOk);
    
            btn.setOnClickListener(newView.OnClickListener() {
    
               public void onClick(View v) {
    
                  v.setVisibility(View.GONE);
    
               }
           });
    

    当值为true的时候点击后的效果

    当设为false的时候

  • 相关阅读:
    洛谷 U138347 贩卖武器
    洛谷 U138346 统治王国
    小技巧—对树中叶子节点的记录
    洛谷 U138345 太极棋
    洛谷 U138343 炼金术士
    CF1038C Gambling
    CF1037A Packets
    如何看待神&#183;QYB自创算法爆锤成名已久的计算机科学家Robert&#183;Tarjan
    浅谈拓扑排序和元素间依赖性
    NOIP 2013 车站分级
  • 原文地址:https://www.cnblogs.com/hawkon/p/1806226.html
Copyright © 2011-2022 走看看