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的時候,父容器將成爲錨點,以父容器做爲佈局的依據。

 

ExpandedBlockStart.gif代碼


<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);

           }
       });
2010082310292686.png

當值爲true的時候點擊後的效果

2010082310300536.png

當設爲false的時候

2010082310303691.png

發佈了57 篇原創文章 · 獲贊 33 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章