当前位置:   article > 正文

android studio 绘制计算器UI_as 计算器ui xml

as 计算器ui xml

效果

在这里插入图片描述

代码解释


android:background="@drawable/shape_rectangle"  引用自己写的背景
android:textSize="30sp"                         字体大小
android:gravity="center"                        字体居正中
android:gravity="center_vertical"               字体居竖直方向的中
android:paddingLeft="50dp"                      设置字体离左边距离

android:shape="rectangle"                       边框为长方形
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

1.drawable 的代码(自己写的背景)

1.shape_color_rectangle

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <solid android:color="#EE7942"/>
    <stroke
        android:color="#333333"
        android:width="1dp"/>
</shape>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

2.shape_rectangle


<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#ffffff"/>

    <stroke
        android:color="#333333"
        android:width="1dp"/>

</shape>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

2.layout 代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:orientation="horizontal">

        <TextView
            android:layout_width="0dp"
            android:layout_height="80dp"
            android:layout_weight="1"
            android:background="@drawable/shape_rectangle"
            android:text="C"
            android:textSize="30sp"
            android:gravity="center"/>



        <TextView
            android:layout_width="0dp"
            android:layout_height="80dp"
            android:layout_weight="1"
            android:background="@drawable/shape_rectangle"
            android:text="+/-"
            android:textSize="30sp"
            android:gravity="center"/>



        <TextView
            android:layout_width="0dp"
            android:layout_height="80dp"
            android:layout_weight="1"
            android:background="@drawable/shape_rectangle"
            android:text="%"
            android:textSize="30sp"
            android:gravity="center"/>



        <TextView
            android:layout_width="0dp"
            android:layout_height="80dp"
            android:layout_weight="1"
            android:background="@drawable/shape_color_rectangle"
            android:text="/"
            android:textSize="30sp"
            android:gravity="center"/>



    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:orientation="horizontal">

        <TextView
            android:layout_width="0dp"
            android:layout_height="80dp"
            android:layout_weight="1"
            android:background="@drawable/shape_rectangle"
            android:text="1"
            android:textSize="30sp"
            android:gravity="center"/>



        <TextView
            android:layout_width="0dp"
            android:layout_height="80dp"
            android:layout_weight="1"
            android:background="@drawable/shape_rectangle"
            android:text="2"
            android:textSize="30sp"
            android:gravity="center"/>



        <TextView
            android:layout_width="0dp"
            android:layout_height="80dp"
            android:layout_weight="1"
            android:background="@drawable/shape_rectangle"
            android:text="3"
            android:textSize="30sp"
            android:gravity="center"/>



        <TextView
            android:layout_width="0dp"
            android:layout_height="80dp"
            android:layout_weight="1"
            android:background="@drawable/shape_color_rectangle"
            android:text="*"
            android:textSize="30sp"
            android:gravity="center"/>



    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:orientation="horizontal">

        <TextView
            android:layout_width="0dp"
            android:layout_height="80dp"
            android:layout_weight="1"
            android:background="@drawable/shape_rectangle"
            android:text="4"
            android:textSize="30sp"
            android:gravity="center"/>



        <TextView
            android:layout_width="0dp"
            android:layout_height="80dp"
            android:layout_weight="1"
            android:background="@drawable/shape_rectangle"
            android:text="5"
            android:textSize="30sp"
            android:gravity="center"/>



        <TextView
            android:layout_width="0dp"
            android:layout_height="80dp"
            android:layout_weight="1"
            android:background="@drawable/shape_rectangle"
            android:text="6"
            android:textSize="30sp"
            android:gravity="center"/>



        <TextView
            android:layout_width="0dp"
            android:layout_height="80dp"
            android:layout_weight="1"
            android:background="@drawable/shape_color_rectangle"
            android:text="-"
            android:textSize="30sp"
            android:gravity="center"/>



    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:orientation="horizontal">

        <TextView
            android:layout_width="0dp"
            android:layout_height="80dp"
            android:layout_weight="1"
            android:background="@drawable/shape_rectangle"
            android:text="7"
            android:textSize="30sp"
            android:gravity="center"/>



        <TextView
            android:layout_width="0dp"
            android:layout_height="80dp"
            android:layout_weight="1"
            android:background="@drawable/shape_rectangle"
            android:text="8"
            android:textSize="30sp"
            android:gravity="center"/>



        <TextView
            android:layout_width="0dp"
            android:layout_height="80dp"
            android:layout_weight="1"
            android:background="@drawable/shape_rectangle"
            android:text="9"
            android:textSize="30sp"
            android:gravity="center"/>



        <TextView
            android:layout_width="0dp"
            android:layout_height="80dp"
            android:layout_weight="1"
            android:background="@drawable/shape_color_rectangle"
            android:text="+"
            android:textSize="30sp"
            android:gravity="center"/>



    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:orientation="horizontal">


        <TextView
            android:layout_width="0dp"
            android:layout_height="80dp"
            android:layout_weight="2"
            android:paddingLeft="50dp"
            android:gravity="center_vertical"
            android:background="@drawable/shape_rectangle"
            android:text="0"
            android:textSize="30sp" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="80dp"
            android:layout_weight="1"
            android:gravity="center"
            android:background="@drawable/shape_rectangle"
            android:text="."
            android:textSize="30sp"/>

        <TextView
            android:layout_width="0dp"
            android:layout_height="80dp"
            android:layout_weight="1"
            android:background="@drawable/shape_color_rectangle"
            android:text="="
            android:textSize="30sp"
            android:gravity="center"/>



    </LinearLayout>

</LinearLayout>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/271934?site
推荐阅读
相关标签
  

闽ICP备14008679号