設置corners_bg.xml
設置邊框圓角可以在drawable-mdpi目錄裏定義一個xml:
1 |
<? xml version = "1.0" encoding = "utf-8" ?> |
2 |
< shape xmlns:android = "http://schemas.android.com/apk/res/android" > |
3 |
< solid android:color = "#FFFFFF" /> |
4 |
< corners android:topLeftRadius = "10dp" |
5 |
android:topRightRadius = "10dp" |
6 |
android:bottomRightRadius = "10dp" |
7 |
android:bottomLeftRadius = "10dp" /> |
8 |
</ shape > |
solid的表示填充顏色,爲了簡單,這裏用的是白色。
而corners則是表示圓角,注意的是這裏bottomRightRadius是左下角而不是右下角,bottomLeftRadius右下角。
上面的效果也可以像下面一樣設置,如下:
1 |
< corners android:radius = "5dp" /> |
引用corners_bg.xml
如果想引用這個xml,只需要@drawable/corners_bg.xml即可:
1 |
android:background="@drawable/corners_bg" |
應用範例
001 |
<? xml version = "1.0" encoding = "utf-8" ?> |
002 |
< LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android" |
003 |
android:layout_width = "match_parent" |
004 |
android:layout_height = "match_parent" |
005 |
android:background = "#E1E0DE" |
006 |
android:orientation = "vertical" > |
007 |
008 |
< TextView |
009 |
android:id = "@+id/textView1" |
010 |
android:layout_width = "match_parent" |
011 |
android:layout_height = "50dp" |
012 |
android:background = "#2B3439" |
013 |
android:gravity = "center" |
014 |
android:text = "發現" |
015 |
android:textColor = "#FFFFFF" |
016 |
android:textSize = "20sp" /> |
017 |
018 |
< LinearLayout |
019 |
android:id = "@+id/login_div" |
020 |
android:layout_width = "fill_parent" |
021 |
android:layout_height = "50dp" |
022 |
android:layout_margin = "10dp" |
023 |
android:background = "@drawable/corners_bg" |
024 |
android:gravity = "center_vertical" |
025 |
android:padding = "10dp" > |
026 |
027 |
< ImageView |
028 |
android:id = "@+id/imageView1" |
029 |
android:layout_width = "wrap_content" |
030 |
android:layout_height = "wrap_content" |
031 |
android:src = "@drawable/find_more_friend_photograph_icon" /> |
032 |
033 |
< TextView |
034 |
android:id = "@+id/textView2" |
035 |
android:layout_width = "wrap_content" |
036 |
android:layout_height = "wrap_content" |
037 |
android:layout_marginLeft = "14dp" |
038 |
android:text = "朋友圈" |
039 |
android:textColor = "#000" |
040 |
android:textSize = "18sp" /> |
041 |
</ LinearLayout > |
042 |
043 |
< LinearLayout |
044 |
android:layout_width = "fill_parent" |
045 |
android:layout_height = "101dp" |
046 |
android:layout_margin = "10dp" |
047 |
android:background = "@drawable/corners_bg" |
048 |
android:orientation = "vertical" |
049 |
android:padding = "10dp" > |
050 |
051 |
< LinearLayout |
052 |
android:layout_width = "wrap_content" |
053 |
android:layout_height = "50dp" > |
054 |
055 |
< ImageView |
056 |
android:layout_width = "wrap_content" |
057 |
android:layout_height = "wrap_content" |
058 |
android:src = "@drawable/find_more_friend_scan" /> |
059 |
060 |
< TextView |
061 |
android:layout_width = "wrap_content" |
062 |
android:layout_height = "wrap_content" |
063 |
android:layout_marginLeft = "14dp" |
064 |
android:text = "掃一掃" |
065 |
android:textColor = "#000" |
066 |
android:textSize = "18sp" /> |
067 |
</ LinearLayout > |
068 |
069 |
< LinearLayout |
070 |
android:layout_width = "wrap_content" |
071 |
android:layout_height = "50dp" |
072 |
android:layout_centerVertical = "true" > |
073 |
074 |
< ImageView |
075 |
android:layout_width = "wrap_content" |
076 |
android:layout_height = "wrap_content" |
077 |
android:src = "@drawable/come_from_shake" /> |
078 |
079 |
< TextView |
080 |
android:layout_width = "wrap_content" |
081 |
android:layout_height = "wrap_content" |
082 |
android:layout_marginLeft = "14dp" |
083 |
android:text = "搖一搖" |
084 |
android:textColor = "#000" |
085 |
android:textSize = "18sp" /> |
086 |
</ LinearLayout > |
087 |
</ LinearLayout > |
088 |
089 |
< LinearLayout |
090 |
android:layout_width = "fill_parent" |
091 |
android:layout_height = "101dp" |
092 |
android:layout_margin = "10dp" |
093 |
android:background = "@drawable/corners_bg" |
094 |
android:orientation = "vertical" |
095 |
android:padding = "10dp" > |
096 |
097 |
< LinearLayout |
098 |
android:layout_width = "wrap_content" |
099 |
android:layout_height = "50dp" > |
100 |
101 |
< ImageView |
102 |
android:layout_width = "wrap_content" |
103 |
android:layout_height = "wrap_content" |
104 |
android:src = "@drawable/find_more_friend_near_icon" /> |
105 |
106 |
< TextView |
107 |
android:layout_width = "wrap_content" |
108 |
android:layout_height = "wrap_content" |
109 |
android:layout_marginLeft = "14dp" |
110 |
android:text = "附近的人" |
111 |
android:textColor = "#000" |
112 |
android:textSize = "18sp" /> |
113 |
</ LinearLayout > |
114 |
115 |
< LinearLayout |
116 |
android:layout_width = "wrap_content" |
117 |
android:layout_height = "50dp" |
118 |
android:layout_centerVertical = "true" > |
119 |
120 |
< ImageView |
121 |
android:layout_width = "wrap_content" |
122 |
android:layout_height = "wrap_content" |
123 |
android:src = "@drawable/come_from_bottle" /> |
124 |
125 |
< TextView |
126 |
android:layout_width = "wrap_content" |
127 |
android:layout_height = "wrap_content" |
128 |
android:layout_marginLeft = "14dp" |
129 |
android:text = "漂流瓶" |
130 |
android:textColor = "#000" |
131 |
android:textSize = "18sp" /> |
132 |
</ LinearLayout > |
133 |
</ LinearLayout > |
134 |
135 |
< LinearLayout |
136 |
android:id = "@+id/login_div" |
137 |
android:layout_width = "fill_parent" |
138 |
android:layout_height = "50dp" |
139 |
android:layout_margin = "10dp" |
140 |
android:background = "@drawable/corners_bg" |
141 |
android:gravity = "center_vertical" |
142 |
android:padding = "10dp" > |
143 |
144 |
< ImageView |
145 |
android:id = "@+id/imageView1" |
146 |
android:layout_width = "wrap_content" |
147 |
android:layout_height = "wrap_content" |
148 |
android:src = "@drawable/more_game" /> |
149 |
150 |
< TextView |
151 |
android:id = "@+id/textView2" |
152 |
android:layout_width = "wrap_content" |
153 |
android:layout_height = "wrap_content" |
154 |
android:layout_marginLeft = "14dp" |
155 |
android:text = "遊戲中心" |
156 |
android:textColor = "#000" |
157 |
android:textSize = "18sp" /> |
158 |
</ LinearLayout > |
159 |
160 |
</ LinearLayout > |