Android編程實(shí)現(xiàn)圓角邊框布局效果的方法
本文實(shí)例講述了Android編程實(shí)現(xiàn)圓角邊框布局效果的方法。分享給大家供大家參考,具體如下:
這里用的是TableLayout布局的。先看效果圖
下面看下布局文件
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#FFFFFF" android:orientation="vertical" > <!-- 表格布局 --> <TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="10dip" > <!-- 表格布局:第一行 --> <TableRow android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/shape_top_corner_no_bottom_line" android:padding="10dip" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginRight="10dip" android:text="姓名:" > </TextView> <EditText android:id="@+id/bankingYourNameEditText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_weight="1" android:background="@null" android:singleLine="true" > </EditText> </TableRow> <!-- 表格布局:第二行 --> <TableRow android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/shape_no_corner_without_bottom" android:padding="10dip" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginRight="10dip" android:text="聯(lián)系電話:" > </TextView> <EditText android:id="@+id/bankingContactTelEditText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_weight="1" android:background="@null" android:inputType="phone" android:singleLine="true" > </EditText> </TableRow> <!-- 表格布局:第三行 --> <TableRow android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/shape_bottom_corner_no_top_line" android:padding="10dip" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginRight="10dip" android:text="聯(lián)系電話:" > </TextView> <EditText android:id="@+id/bankingContactTelEditText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_weight="1" android:background="@null" android:inputType="phone" android:singleLine="true" > </EditText> </TableRow> </TableLayout> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="Button" /> </LinearLayout>
表格布局中每個(gè)TableRow表示一行,TableRow中的每個(gè)基本控件都是一列,這是一個(gè)三行兩列的布局
這里的表格背景是自定義的shape,下面分別看一下三個(gè)shape的代碼。
shape_top_corner_no_bottom_line.xml文件:頂部帶圓角 白色背景 灰色邊框 無下邊框 長(zhǎng)方體
<?xml version="1.0" encoding="UTF-8"?> <!-- 頂部帶圓角 白色背景 灰色邊框 無下邊框 長(zhǎng)方體 --> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape> <solid android:color="#FFFFFF" /> <corners android:topLeftRadius="10dp" android:topRightRadius="10dp" android:bottomRightRadius="0.1dp" android:bottomLeftRadius="0.1dp" /> <stroke android:width="1dp" android:color="#ffa8abad" /> </shape> </item> <item android:top="1dp" android:left="1dp" android:right="1dp"> <shape> <solid android:color="#FFFFFF" /> <corners android:topLeftRadius="10dp" android:topRightRadius="10dp" android:bottomRightRadius="0.1dp" android:bottomLeftRadius="0.1dp" /> <stroke android:width="1dp" android:color="#ffffffff" /> </shape> </item> </layer-list>
shape_no_corner_without_bottom.xml文件:不帶圓角 白色背景 灰色邊框 無下邊框 長(zhǎng)方體
<?xml version="1.0" encoding="UTF-8"?> <!-- 不帶圓角 白色背景 灰色邊框 無下邊框 長(zhǎng)方體 --> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <shape> <solid android:color="#FFFFFF" /> <stroke android:width="1dp" android:color="#ffa8abad" /> </shape> </item> <item android:left="1dp" android:right="1dp" android:top="1dp"> <shape> <solid android:color="#FFFFFF" /> <stroke android:width="1dp" android:color="#ffffffff" /> </shape> </item> </layer-list>
shape_bottom_corner_no_top_line.xml文件:底部圓角 白色背景 灰色邊框 長(zhǎng)方體
<?xml version="1.0" encoding="UTF-8"?> <!-- 底部圓角 白色背景 灰色邊框 長(zhǎng)方體 --> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape> <solid android:color="#FFFFFF" /> <corners android:topLeftRadius="0.1dp" android:topRightRadius="0.1dp" android:bottomRightRadius="10dp" android:bottomLeftRadius="10dp" /> <stroke android:width="1dp" android:color="#ffa8abad" /> </shape> </item> <item android:top="1dp" android:bottom="1dp" android:left="1dp" android:right="1dp"> <shape> <solid android:color="#FFFFFF" /> <corners android:topLeftRadius="0.1dp" android:topRightRadius="0.1dp" android:bottomRightRadius="10dp" android:bottomLeftRadius="10dp" /> <stroke android:width="1dp" android:color="#ffffffff" /> </shape> </item> </layer-list>
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android布局layout技巧總結(jié)》、《Android開發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。
- Android手機(jī)顯示多彩霓虹燈效果
- Android Shader應(yīng)用開發(fā)之霓虹閃爍文字效果
- Android圖像處理之霓虹濾鏡效果
- Android布局之幀布局FrameLayout詳解
- Android布局之FrameLayout幀布局
- Android實(shí)現(xiàn)氣泡布局/彈窗效果 氣泡尖角方向及偏移量可控
- Android布局實(shí)現(xiàn)圓角邊框效果
- Android動(dòng)畫效果之自定義ViewGroup添加布局動(dòng)畫(五)
- Android給布局、控件加陰影效果的示例代碼
- Android布局控件DrawerLayout實(shí)現(xiàn)完美側(cè)滑效果
- Android開發(fā)實(shí)現(xiàn)布局幀布局霓虹燈效果示例
相關(guān)文章
Android開發(fā)實(shí)現(xiàn)瀏覽器全屏顯示功能
這篇文章主要介紹了Android開發(fā)實(shí)現(xiàn)瀏覽器全屏顯示功能,涉及Android布局修改及相關(guān)屬性動(dòng)態(tài)設(shè)置操作技巧,需要的朋友可以參考下2017-09-09Android源碼中final關(guān)鍵字的用法及final,finally,finalize的區(qū)別
Android的源碼中很多地方對(duì)final關(guān)鍵字的用法很是“別出心裁”,之所以這么說是因?yàn)槲覐臎]看過是這么使用final關(guān)鍵字的,通過本文給大家分享Android源碼中final關(guān)鍵字的用法及final,finally,finalize的區(qū)別,感興趣的朋友一起學(xué)習(xí)吧2015-12-12Android利用代碼控制設(shè)備上其他音樂播放器的方法
這篇文章主要給大家介紹了關(guān)于Android利用代碼如何控制設(shè)備上其他音樂播放器的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-06-06Android框架Volley使用:ImageRequest請(qǐng)求實(shí)現(xiàn)圖片加載
這篇文章主要介紹了Android框架Volley使用:ImageRequest請(qǐng)求實(shí)現(xiàn)圖片加載的相關(guān)知識(shí),非常不錯(cuò),具有一定的參考借鑒價(jià)值 ,需要的朋友可以參考下2019-05-05簡(jiǎn)單實(shí)現(xiàn)Android讀取網(wǎng)絡(luò)圖片到本地
這篇文章主要為大家詳細(xì)介紹了如何簡(jiǎn)單實(shí)現(xiàn)Android讀取網(wǎng)絡(luò)圖片到本地的方法,感興趣的小伙伴們可以參考一下2016-08-08Android 完全退出當(dāng)前應(yīng)用程序的四種方法
Android程序有很多Activity,比如說主窗口A,調(diào)用了子窗口B,如果在B中直接finish(), 接下里顯示的是A。在B中如何關(guān)閉整個(gè)Android應(yīng)用程序呢?本人總結(jié)了幾種比較簡(jiǎn)單的實(shí)現(xiàn)方法2016-02-02Android簡(jiǎn)單實(shí)現(xiàn)無限滾動(dòng)自動(dòng)滾動(dòng)的ViewPager
這篇文章主要介紹了Android簡(jiǎn)單實(shí)現(xiàn)無限滾動(dòng)自動(dòng)滾動(dòng)的ViewPager,百度谷歌上面也有很多關(guān)于這方面的教程,但是感覺都略顯麻煩,而且封裝的都不是很徹底。所以試著封裝一個(gè)比較好用的ViewPager,實(shí)現(xiàn)思路一起通過本文學(xué)習(xí)吧2016-12-12Android實(shí)現(xiàn)為Tab添加Menu的方法
這篇文章主要介紹了Android實(shí)現(xiàn)為Tab添加Menu的方法,分析了兩種解決方法的思路并對(duì)比分析了相應(yīng)的優(yōu)缺點(diǎn),具有一定參考借鑒價(jià)值,需要的朋友可以參考下2016-10-10Android使用ViewPager完成app引導(dǎo)頁
這篇文章主要為大家詳細(xì)介紹了Android使用ViewPager完成app引導(dǎo)頁,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-11-11