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的时候

  • 相关阅读:
    图上两点之间的第k最短路径的长度 ACM-ICPC 2018 沈阳赛区网络预赛 D. Made In Heaven
    ACM-ICPC 2018 徐州赛区网络预赛 B. BE, GE or NE
    poj 1986
    ACM-ICPC 2018 徐州赛区网络预赛 A. Hard to prepare
    ACM-ICPC 2018 徐州赛区网络预赛 G. Trace
    hdu 5533
    ACM Changchun 2015 L . House Building
    ACM Changchun 2015 J. Chip Factory
    一些小程序
    ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn't want to study
  • 原文地址:https://www.cnblogs.com/hawkon/p/1806226.html
Copyright © 2011-2022 走看看