Android 相对布局别自己快遗忘的属性layout_alignRight,layout_alignBottom,layout_alignTop,layout_alignLeft
今天在群里看到有人提到layout_alignRight 這種屬性,自己想了半天居然沒有了印象
趕緊寫一個布局看看這個相對布局的屬性
?先看下自己常用的屬性
?android:alignParentBottom
?android:layout_alignParentLeft?
?android:layout_alignParentRight
?android:layout_alignParentTop??
這四個控件一般屬性設置為true 它們相對于父布局的相對位置 ,它們的屬性依賴于父布局的RelativeLayout
在看 下面的屬性
android:layout_alignRight
android:layout_alignBottom
android:layout_alignTop
android:layout_alignLeft
它們的屬性一般相對于指定id的位置,不依賴與父布局的RelativeLayout?
想入現(xiàn)在 一個相對布局寬和高都是match_parent
畫下面的圖
textView 使用android:layout_alignParentRight 位于了右邊 但是高度不好設置了
當然大家一般都不會把最外的層的相對布局高度設為為match_parent
這個時候使用相對某個控件的設置還是很好使用的
代碼如下
android:layout_alignTop="@+id/edt"
android:layout_alignRight="@+id/edt"
android:layout_alignBottom="@+id/edt"
<RelativeLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"><EditTextandroid:id="@+id/edt"android:layout_width="400dp"android:layout_height="100dp"android:background="@null"android:hint="請輸入手機號" /><TextViewandroid:id="@+id/txt"android:layout_width="100dp"android:layout_height="match_parent"android:layout_alignTop="@+id/edt"android:layout_alignRight="@+id/edt"android:layout_alignBottom="@+id/edt"android:layout_marginTop="25dp"android:layout_marginRight="30dp"android:layout_marginBottom="25dp"android:background="@drawable/drawable_txt"android:gravity="center"android:text="獲取驗證碼" /></RelativeLayout>
這個就是相對于某一個控件的id 來控制很不錯的選擇,比如購物車上的數(shù)量,等等,方法有很多中,這種方法必能被遺忘
學而時習之,溫故而知新。。。
?
總結(jié)
以上是生活随笔為你收集整理的Android 相对布局别自己快遗忘的属性layout_alignRight,layout_alignBottom,layout_alignTop,layout_alignLeft的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 铁观音多少钱一斤啊?
- 下一篇: Android 购物车图片上面添加数字