亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 系統 > Android > 正文

Android制作漂亮自適布局鍵盤的方法

2020-04-11 11:09:49
字體:
來源:轉載
供稿:網友

最近做了個自定義鍵盤,但面對不同分辨率的機型其中數字鍵盤不能根據界面大小自已鋪滿,但又不能每種機型都做一套吧,所以要做成自適應,那這里主講思路。

這里最上面的titlebar高度固定,下面輸入的金額高度也固定(當然也可以自適應),主要是中間的數字鍵盤,高度和寬度需要自適應。先來張效果圖:

最常見的解決方案是用線性布局,自適應當然是按比例,但布局中無%的概念,那就要用到layout_weight了,該屬性的作用是決定控件在其父布局中的顯示權重(具體概念就不多說了)。

  這里用一個LinearLayout 將數字鍵盤與下面的支付類型進行包裝,然后用一個大LinearLayout包住所有的數字鍵盤如下圖,它與下面支付類型比例是6:1,這樣數字鍵盤就會按屏幕大小高度與寬度進行變化,每一行數字鍵盤用一個LinearLayout,里面包3個數字顯示Button按鈕。

設置每行的LinearLayout的layout_height=0dp,layout_weight=1,具體設置如下:

 <style name="layout_input_amount_style">  <item name="android:layout_width">match_parent</item>  <item name="android:layout_height">0dp</item>  <item name="android:layout_weight">1</item>  <item name="android:layout_marginBottom">1dp</item>  <item name="android:gravity">center</item>  <item name="android:orientation">horizontal</item> </style>

  這樣就保證了上下自適應布局。然后行里面的Button也是平均分配,不過這里是橫向布局:layout_width=0dp,layout_weight=1,具體設置如下:

<style name="btn_input_amount_style">  <item name="android:layout_width">0dp</item>  <item name="android:layout_height">match_parent</item>  <item name="android:layout_weight">1</item>  <item name="android:textSize">40sp</item>  <item name="android:textColor">#333333</item>  <item name="android:background">@color/white</item> </style>

  這樣就達到了上面的數字鍵盤的上下左右自適應了?,F在的問題是其中的灰色邊框怎么出來呢?TextView中沒有設置border的屬性,網上找的方法又很麻煩。

  這里需要用到一個技巧,利用灰色背景,讓兩個按鍵間的margin=1,上下也是margin=1,但是最右邊的3、6、9和最后一行不用加。

<Button android:id="@+id/btn_1" style="@style/btn_input_amount_style" android:layout_marginRight="1dp" android:text="1" />

   為什么要設置layout_width=0dp?結合layout_weight,可以使控件成正比例顯示,輕松解決了當前Android開發最為頭疼的碎片化問題之一。如果設置成wrap_content,內容過長會導致上下無法對齊的情況。

  下面為整個布局內容:

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.view.InputAmountActivity"> <RelativeLayout  android:id="@+id/bar_input"  android:layout_width="match_parent"  android:layout_height="@dimen/title_bar_height"  android:background="@color/logo_background"  android:orientation="horizontal">  <TextView   android:id="@+id/bar_back"   android:layout_width="wrap_content"   android:layout_height="match_parent"   android:background="@color/transparent"   android:drawableLeft="@drawable/btn_back_detail"   android:paddingLeft="17dip"   android:paddingRight="17dip" />  <TextView   android:id="@+id/bar_title"   style="@style/title_text_style"   android:layout_width="wrap_content"   android:layout_height="wrap_content"   android:layout_centerInParent="true"   android:layout_marginLeft="50dp"   android:layout_marginRight="50dp"   android:singleLine="true"   android:text="輸入金額" /> </RelativeLayout> <LinearLayout  android:id="@+id/txt_amount"  android:layout_width="match_parent"  android:layout_height="wrap_content"  android:layout_below="@id/bar_input"  android:background="@color/logo_background">  <TextView   android:id="@+id/txt_pay_amount"   android:layout_width="match_parent"   android:layout_height="115dp"   android:background="@color/transparent"   android:gravity="right|center"   android:paddingLeft="17dip"   android:paddingRight="20dp"   android:text="¥998"   android:textColor="@color/white"   android:textSize="40sp"   android:textStyle="bold" /> </LinearLayout> <LinearLayout  android:layout_width="match_parent"  android:layout_height="match_parent"  android:layout_below="@id/txt_amount"  android:orientation="vertical">  <LinearLayout   android:id="@+id/table_num"   android:layout_width="match_parent"   android:layout_height="match_parent"   android:layout_weight="6"   android:background="#c8cbcc"   android:orientation="vertical">   <LinearLayout style="@style/layout_input_amount_style">    <Button     android:id="@+id/btn_1"     style="@style/btn_input_amount_style"     android:layout_marginRight="1dp"     android:text="1" />    <Button     android:id="@+id/btn_2"     style="@style/btn_input_amount_style"     android:layout_marginRight="1dp"     android:text="2" />    <Button     android:id="@+id/btn_3"     style="@style/btn_input_amount_style"     android:text="3" />   </LinearLayout>   <LinearLayout style="@style/layout_input_amount_style">    <Button     android:id="@+id/btn_4"     style="@style/btn_input_amount_style"     android:layout_marginRight="1dp"     android:text="4" />    <Button     android:id="@+id/btn_5"     style="@style/btn_input_amount_style"     android:layout_marginRight="1dp"     android:text="5" />    <Button     android:id="@+id/btn_6"     style="@style/btn_input_amount_style"     android:text="6" />   </LinearLayout>   <LinearLayout style="@style/layout_input_amount_style">    <Button     android:id="@+id/btn_7"     style="@style/btn_input_amount_style"     android:layout_marginRight="1dp"     android:text="7" />    <Button     android:id="@+id/btn_8"     style="@style/btn_input_amount_style"     android:layout_marginRight="1dp"     android:text="8" />    <Button     android:id="@+id/btn_9"     style="@style/btn_input_amount_style"     android:text="9" />   </LinearLayout>   <LinearLayout style="@style/layout_input_amount_style">    <Button     android:id="@+id/btn_t"     style="@style/btn_input_amount_style"     android:layout_marginRight="1dp"     android:text="." />    <Button     android:id="@+id/btn_0"     style="@style/btn_input_amount_style"     android:layout_marginRight="1dp"     android:text="0" />    <ImageButton     android:id="@+id/btn_d"     style="@style/btn_input_amount_style"     android:src="@drawable/ico_del" />   </LinearLayout>  </LinearLayout>  <LinearLayout   android:layout_width="match_parent"   android:layout_height="68dp"   android:layout_weight="1"   android:orientation="horizontal">   <LinearLayout    android:id="@+id/layout_zhifubao"    android:layout_width="0dp"    android:layout_height="wrap_content"    android:layout_weight="1"    android:background="@color/logo_background"    android:gravity="center"    android:orientation="vertical">    <ImageView     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_marginTop="9dp"     android:src="@drawable/ico_zhifubao" />    <TextView     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_marginBottom="9dp"     android:text="支付寶"     android:textColor="@color/white"     android:textSize="12sp" />   </LinearLayout>   <LinearLayout    android:id="@+id/layout_wechat"    android:layout_width="0dp"    android:layout_height="wrap_content"    android:layout_weight="1"    android:background="#3cb034"    android:gravity="center"    android:orientation="vertical">    <ImageView     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_marginTop="9dp"     android:src="@drawable/ico_wechat" />    <TextView     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_marginBottom="9dp"     android:text="微信"     android:textColor="@color/white"     android:textSize="12sp" />   </LinearLayout>   <LinearLayout    android:id="@+id/layout_pay"    android:layout_width="0dp"    android:layout_height="wrap_content"    android:layout_weight="1"    android:background="#ff7700"    android:gravity="center"    android:orientation="vertical">    <ImageView     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_marginTop="9dp"     android:src="@drawable/ico_pay" />    <TextView     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_marginBottom="9dp"     android:text="儲值"     android:textColor="@color/white"     android:textSize="12sp" />   </LinearLayout>  </LinearLayout> </LinearLayout></RelativeLayout>

  是不是很酷?

  圖標什么的自己上網找吧,這里就不貼出來了。

Android制作漂亮自適布局鍵盤的方法就先給大家介紹到這里,后續還會持續更新相關知識,希望大家繼續關注武林網網站,謝謝!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
欧美裸身视频免费观看| 亚洲理论电影网| 成人欧美一区二区三区在线湿哒哒| 国产91色在线|免| 成人一区二区电影| 久久久久久成人| 久久中国妇女中文字幕| 精品久久在线播放| 欧美孕妇性xx| 国产福利视频一区二区| 精品无人区太爽高潮在线播放| 97精品国产aⅴ7777| 成人黄色av网站| 国产精品久久中文| 欧美裸体视频网站| 91精品啪在线观看麻豆免费| 久久影视电视剧凤归四时歌| 成人国内精品久久久久一区| 色综合久久精品亚洲国产| 精品自拍视频在线观看| 欧美极度另类性三渗透| 97在线视频观看| 97免费在线视频| 5278欧美一区二区三区| 日韩av综合网| 亚洲国产精品yw在线观看| 国产做受高潮69| 国产精品久久久久久亚洲调教| 日韩小视频在线观看| 亚洲图片欧美日产| 欧美性猛交xxxx| 久久婷婷国产麻豆91天堂| 亚洲视频在线看| 日韩激情av在线播放| 欧美综合一区第一页| 国产精品电影一区| 成人性生交大片免费看视频直播| 成人精品视频在线| 久久精品亚洲94久久精品| 久久国产精品免费视频| 国产香蕉一区二区三区在线视频| 8x拔播拔播x8国产精品| 亚洲成人久久一区| 久久久国产一区二区三区| 欧美性xxxxx| 国产精品欧美日韩| 亚洲精品www久久久| 琪琪亚洲精品午夜在线| 少妇高潮久久久久久潘金莲| 动漫精品一区二区| 欧美在线一级va免费观看| 亚洲人成在线观看| 日韩一级黄色av| 精品伊人久久97| 日韩女在线观看| 日韩网站免费观看高清| 在线观看日韩欧美| 欧美激情亚洲另类| 成人黄色av免费在线观看| 日韩av电影在线免费播放| 国产日韩精品一区二区| 欧美日韩午夜剧场| 国产精品自产拍在线观| 亚洲电影免费观看| 亚洲精品之草原avav久久| 成人免费视频a| 欧美极品美女视频网站在线观看免费| 88国产精品欧美一区二区三区| 日本欧美黄网站| 91成人在线播放| 欧美国产欧美亚洲国产日韩mv天天看完整| 成人欧美一区二区三区黑人孕妇| 亚洲精品aⅴ中文字幕乱码| 国产精品免费电影| 久久久久久久久久久成人| 热久久这里只有精品| 欧美日韩国产中文精品字幕自在自线| 国产精品一区二区三区免费视频| 久久久久国产精品一区| 亚洲bt欧美bt日本bt| 亚洲国产欧美久久| 中文字幕自拍vr一区二区三区| 久久久极品av| 91精品国产亚洲| 亚洲999一在线观看www| 久久91超碰青草是什么| 欧美一乱一性一交一视频| 97人人模人人爽人人喊中文字| 欧美自拍视频在线观看| 欧美二区乱c黑人| 欧美黄色三级网站| 国模私拍视频一区| 日韩欧美一区二区三区| 中文字幕欧美日韩va免费视频| 日韩欧美成人网| 成人h片在线播放免费网站| 亚洲精品98久久久久久中文字幕| 国产日产亚洲精品| 亚洲国产精品久久久| 大桥未久av一区二区三区| 成人免费看吃奶视频网站| 国产在线a不卡| 日韩黄色av网站| 国产精品一区二区女厕厕| 91中文字幕一区| 亚洲а∨天堂久久精品9966| 久久成人18免费网站| 欧美日韩成人精品| 国产精品稀缺呦系列在线| 精品久久久久久久久久久久久久| 日韩欧美国产免费播放| 欧美高清第一页| 精品欧美一区二区三区| 久久久亚洲欧洲日产国码aⅴ| 欧美成人网在线| 亚洲无限乱码一二三四麻| 国产精品视频免费在线| 亚洲精品视频在线观看视频| 91国语精品自产拍在线观看性色| 欧美精品videossex88| 青青a在线精品免费观看| 欧美一区二区影院| 97在线看福利| 国产成+人+综合+亚洲欧洲| 中文字幕日韩精品在线观看| 97久久久免费福利网址| 狠狠色狠狠色综合日日小说| 国产精选久久久久久| 97在线免费视频| 国产精品夫妻激情| 91黑丝高跟在线| 日韩av影片在线观看| 日韩免费中文字幕| 国产精品一区二区久久| 超碰91人人草人人干| 亚洲国产精品久久久久秋霞蜜臀| 正在播放国产一区| 日韩暖暖在线视频| 在线观看中文字幕亚洲| 中文字幕精品网| 国产精品视频久久久久| 欧美激情第一页xxx| 日韩欧美在线观看| 国产91色在线| 国产精品一区二区在线| 97精品国产97久久久久久免费| 91九色国产社区在线观看| 国产精品电影一区| 亚洲国产精品中文| 国产一区二区三区精品久久久| 国产脚交av在线一区二区| 亚洲图中文字幕| 久久99热这里只有精品国产| 亚州欧美日韩中文视频| 这里只有精品在线播放| 亚洲人成在线播放| 色久欧美在线视频观看| 精品国产91久久久| 亚洲一区二区三区视频| 日韩亚洲成人av在线| 午夜精品99久久免费| 久久亚洲综合国产精品99麻豆精品福利| 一本一本久久a久久精品牛牛影视| 久久久久久网址|