zoukankan      html  css  js  c++  java
  • Android之页面布局

    第一次写博客,没想好从哪儿开始写。正好在学简单的安卓开发,就一点一点把学的内容记录下来。环境都是在Android Studio上完成。有时间就把遇上的坑和心得也都写上来。代码写的一般请不要嫌弃,还有,这些代码都是亲手运行过的,完全ok。

    (1)按照图形实现以下页面布局

    要求: 使用线性布局,可用使用<TextView>标签的android:layout_height=”fill_parent”属性来实现列的填充,可以使用<TextView>标签的android:background=”#RGB”属性来设置颜色

     1 <?xml version="1.0" encoding="utf-8"?>
     2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     3     android:layout_width="match_parent"
     4     android:layout_height="match_parent"
     5     android:orientation="horizontal">
     6 
     7 
     8     <TextView
     9         android:id="@+id/textView"
    10         android:layout_width="wrap_content"
    11         android:layout_height="fill_parent"
    12         android:layout_weight="1"
    13         android:background="#FF0000"
    14         android:text="TextView1" />
    15 
    16     <TextView
    17         android:id="@+id/textView2"
    18         android:layout_width="wrap_content"
    19         android:layout_height="fill_parent"
    20         android:layout_weight="1"
    21         android:background="#FFFFFF"
    22         android:text="TextView2" />
    23 
    24     <TextView
    25         android:id="@+id/textView3"
    26         android:layout_width="wrap_content"
    27         android:layout_height="fill_parent"
    28         android:layout_weight="1"
    29         android:background="#0000EE"
    30         android:text="TextView3" />
    31 
    32     <TextView
    33         android:id="@+id/textView4"
    34         android:layout_width="wrap_content"
    35         android:layout_height="fill_parent"
    36         android:layout_weight="1"
    37         android:background="#000000"
    38         android:text="TextView4" />
    39 </LinearLayout>

    (2)按照下面图形实现一个简单的计算器键盘界面 

    要求: 使用嵌套的线性布局 不用填充背景颜色,数字与符号的顺序可以适当调整,但整体需要填充满页面。

      1 <?xml version="1.0" encoding="utf-8"?>
      2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      3     android:layout_width="match_parent"
      4     android:layout_height="match_parent">
      5 
      6     <LinearLayout
      7         android:layout_width="match_parent"
      8         android:layout_height="match_parent"
      9         android:orientation="vertical">
     10 
     11         <LinearLayout
     12             android:layout_width="match_parent"
     13             android:layout_height="144dp"
     14             android:orientation="horizontal">
     15 
     16             <Button
     17                 android:id="@+id/button6"
     18                 android:layout_width="wrap_content"
     19                 android:layout_height="90dp"
     20                 android:layout_marginTop="60dp"
     21                 android:layout_marginRight="5dp"
     22                 android:layout_weight="1"
     23                 android:text="c" />
     24 
     25             <Button
     26                 android:id="@+id/button7"
     27                 android:layout_width="wrap_content"
     28                 android:layout_height="90dp"
     29                 android:layout_marginTop="60dp"
     30                 android:layout_marginRight="5dp"
     31                 android:layout_weight="1"
     32                 android:text="/" />
     33 
     34             <Button
     35                 android:id="@+id/button8"
     36                 android:layout_width="wrap_content"
     37                 android:layout_height="90dp"
     38                 android:layout_marginTop="60dp"
     39                 android:layout_marginRight="5dp"
     40                 android:layout_weight="1"
     41                 android:text="*" />
     42 
     43             <Button
     44                 android:id="@+id/button9"
     45                 android:layout_width="wrap_content"
     46                 android:layout_height="90dp"
     47                 android:layout_marginTop="60dp"
     48                 android:layout_weight="1"
     49                 android:text="del" />
     50 
     51         </LinearLayout>
     52 
     53         <LinearLayout
     54             android:layout_width="match_parent"
     55             android:layout_height="90dp"
     56             android:orientation="horizontal">
     57 
     58             <Button
     59                 android:id="@+id/button21"
     60                 android:layout_width="wrap_content"
     61                 android:layout_height="90dp"
     62                 android:layout_marginTop="5dp"
     63                 android:layout_marginRight="5dp"
     64                 android:layout_weight="1"
     65                 android:text="7" />
     66 
     67             <Button
     68                 android:id="@+id/button19"
     69                 android:layout_width="wrap_content"
     70                 android:layout_height="90dp"
     71                 android:layout_marginTop="5dp"
     72                 android:layout_marginRight="5dp"
     73                 android:layout_weight="1"
     74                 android:text="8" />
     75 
     76             <Button
     77                 android:id="@+id/button15"
     78                 android:layout_width="wrap_content"
     79                 android:layout_height="90dp"
     80                 android:layout_marginTop="5dp"
     81                 android:layout_marginRight="5dp"
     82                 android:layout_weight="1"
     83                 android:text="9" />
     84 
     85             <Button
     86                 android:id="@+id/button11"
     87                 android:layout_width="wrap_content"
     88                 android:layout_height="90dp"
     89                 android:layout_marginTop="5dp"
     90                 android:layout_weight="1"
     91                 android:text="—" />
     92         </LinearLayout>
     93 
     94         <LinearLayout
     95             android:layout_width="match_parent"
     96             android:layout_height="90dp"
     97             android:orientation="horizontal">
     98             <Button
     99                 android:id="@+id/button29"
    100                 android:layout_width="wrap_content"
    101                 android:layout_height="90dp"
    102                 android:layout_marginTop="5dp"
    103                 android:layout_marginRight="5dp"
    104                 android:layout_weight="1"
    105                 android:text="4" />
    106 
    107             <Button
    108                 android:id="@+id/button30"
    109                 android:layout_width="wrap_content"
    110                 android:layout_height="90dp"
    111                 android:layout_marginTop="5dp"
    112                 android:layout_marginRight="5dp"
    113                 android:layout_weight="1"
    114                 android:text="5" />
    115 
    116             <Button
    117                 android:id="@+id/button31"
    118                 android:layout_width="wrap_content"
    119                 android:layout_height="90dp"
    120                 android:layout_marginTop="5dp"
    121                 android:layout_marginRight="5dp"
    122                 android:layout_weight="1"
    123                 android:text="6" />
    124 
    125             <Button
    126                 android:id="@+id/button32"
    127                 android:layout_width="wrap_content"
    128                 android:layout_height="90dp"
    129                 android:layout_marginTop="5dp"
    130                 android:layout_weight="1"
    131                 android:layout_centerHorizontal="true"
    132                 android:text="+" />
    133         </LinearLayout>
    134 
    135         <LinearLayout
    136             android:layout_width="match_parent"
    137             android:layout_height="240dp"
    138             android:orientation="horizontal">
    139 
    140             <TableLayout
    141                 android:layout_width="275dp"
    142                 android:layout_height="240dp"
    143                 android:stretchColumns="2">
    144 
    145                 <LinearLayout
    146                     android:layout_width="match_parent"
    147                     android:layout_height="90dp"
    148                     android:orientation="horizontal">
    149 
    150                     <Button
    151                         android:id="@+id/button33"
    152                         android:layout_width="wrap_content"
    153                         android:layout_height="90dp"
    154                         android:layout_marginTop="5dp"
    155                         android:layout_marginRight="5dp"
    156                         android:layout_weight="1"
    157                         android:text="1" />
    158 
    159                     <Button
    160                         android:id="@+id/button34"
    161                         android:layout_width="wrap_content"
    162                         android:layout_height="90dp"
    163                         android:layout_marginTop="5dp"
    164                         android:layout_marginRight="5dp"
    165                         android:layout_weight="1"
    166                         android:text="2" />
    167 
    168                     <Button
    169                         android:id="@+id/button35"
    170                         android:layout_width="wrap_content"
    171                         android:layout_height="90dp"
    172                         android:layout_marginTop="5dp"
    173                         android:layout_marginRight="6dp"
    174                         android:layout_weight="1"
    175                         android:text="3" />
    176                 </LinearLayout>
    177 
    178                 <LinearLayout
    179                     android:layout_width="match_parent"
    180                     android:layout_height="90dp"
    181                     android:orientation="horizontal">
    182 
    183                     <Button
    184                         android:id="@+id/button38"
    185                         android:layout_width="180dp"
    186                         android:layout_height="90dp"
    187                         android:layout_marginTop="5dp"
    188                         android:layout_marginRight="5dp"
    189                         android:layout_weight="1"
    190                         android:text="0" />
    191 
    192                     <Button
    193                         android:id="@+id/button39"
    194                         android:layout_width="wrap_content"
    195                         android:layout_height="90dp"
    196                         android:layout_marginTop="5dp"
    197                         android:layout_marginRight="5dp"
    198                         android:layout_weight="1"
    199                         android:text="." />
    200                 </LinearLayout>
    201 
    202             </TableLayout>
    203 
    204             <Button
    205                 android:id="@+id/button47"
    206                 android:layout_width="wrap_content"
    207                 android:layout_height="180dp"
    208                 android:layout_marginTop="5dp"
    209                 android:layout_weight="1"
    210                 android:text="=" />
    211 
    212         </LinearLayout>
    213 
    214     </LinearLayout>
    215 
    216 
    217 
    218 </RelativeLayout>

    加油!希望未来可期!

  • 相关阅读:
    leetcode231 2的幂 leetcode342 4的幂 leetcode326 3的幂
    leetcode300. Longest Increasing Subsequence 最长递增子序列 、674. Longest Continuous Increasing Subsequence
    leetcode64. Minimum Path Sum
    leetcode 20 括号匹配
    算法题待做
    leetcode 121. Best Time to Buy and Sell Stock 、122.Best Time to Buy and Sell Stock II 、309. Best Time to Buy and Sell Stock with Cooldown 、714. Best Time to Buy and Sell Stock with Transaction Fee
    rand7生成rand10,rand1生成rand6,rand2生成rand5(包含了rand2生成rand3)
    依图
    leetcode 1.Two Sum 、167. Two Sum II
    从分类,排序,top-k多个方面对推荐算法稳定性的评价
  • 原文地址:https://www.cnblogs.com/rebirther/p/12871714.html
Copyright © 2011-2022 走看看