阿闷 2015-04-09 07:17 采纳率: 0%
浏览 2114
已采纳

android线性布局(计算器ui)

图片说明
以上是效果图:
下面是我的代码,求指教:
<?xml version="1.0" encoding="utf-8"?>
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

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

    <EditText 
        android:id="@+id/msg" android:layout_width="match_parent"
        android:layout_height="wrap_content" android:hint="@null" />
</LinearLayout>

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


    <Button android:layout_width="match_parent"
        android:layout_height="wrap_content" android:text="@+string/m_c"
        android:layout_weight="1"></Button>

    <Button android:layout_width="match_parent"
        android:layout_height="wrap_content" android:text="m+"
        android:layout_weight="1"></Button>

    <Button android:layout_width="match_parent"
        android:layout_height="wrap_content" android:text="m-"
        android:layout_weight="1"></Button>

    <Button android:layout_width="match_parent"
        android:layout_height="wrap_content" android:text="mr"
        android:layout_weight="1"></Button>
</LinearLayout>

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


    <Button android:layout_width="match_parent"
        android:layout_height="wrap_content" android:text="c"
        android:layout_weight="1"></Button>

    <Button android:layout_width="match_parent"
        android:layout_height="wrap_content" android:text="+/-"
        android:layout_weight="1"></Button>

    <Button android:layout_width="match_parent"
        android:layout_height="wrap_content" android:text="/*"
        android:layout_weight="1"></Button>

    <Button android:layout_width="match_parent"
        android:layout_height="wrap_content" android:text="*"
        android:layout_weight="1"></Button>
</LinearLayout>

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


    <Button android:layout_width="match_parent"
        android:layout_height="wrap_content" android:text="7"
        android:layout_weight="1"></Button>

    <Button android:layout_width="match_parent"
        android:layout_height="wrap_content" android:text="8"
        android:layout_weight="1"></Button>

    <Button android:layout_width="match_parent"
        android:layout_height="wrap_content" android:text="9"
        android:layout_weight="1"></Button>

    <Button android:layout_width="match_parent"
        android:layout_height="wrap_content" android:text="-"
        android:layout_weight="1"></Button>
</LinearLayout>

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


    <Button android:layout_width="match_parent"
        android:layout_height="wrap_content" android:text="4"
        android:layout_weight="1"></Button>

    <Button android:layout_width="match_parent"
        android:layout_height="wrap_content" android:text="5"
        android:layout_weight="1"></Button>

    <Button android:layout_width="match_parent"
        android:layout_height="wrap_content" android:text="6"
        android:layout_weight="1"></Button>

    <Button android:layout_width="match_parent"
        android:layout_height="wrap_content" android:text="+    "
        android:layout_weight="1"></Button>
</LinearLayout>

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

        <LinearLayout android:layout_width="wrap_content"
             android:layout_height="wrap_content" android:orientation="vertical"
             android:layout_weight="3"> 

            <LinearLayout android:layout_width="match_parent"
                 android:layout_height="match_parent" android:orientation="horizontal">
                 <Button android:layout_width="match_parent"
                    android:layout_height="wrap_content" android:layout_weight="1"
                    android:text="0"></Button>
                 <Button android:layout_width="match_parent"
                    android:layout_height="wrap_content" android:layout_weight="1"
                    android:text="0"></Button>
                 <Button android:layout_width="match_parent"
                    android:layout_height="wrap_content" android:layout_weight="1"
                    android:text="0"></Button>

            </LinearLayout>  



        </LinearLayout>             
</LinearLayout>  

  • 写回答

2条回答 默认 最新

  • danielinbiti 2015-04-09 07:39
    关注

    最后一段,没环境,没有测试过。layout_weight注意一下,如果一个区域分2部分,其中一个要占4分之3,则那个区域要设1(越小占比越大),另一个要设3

     <LinearLayout android:layout_width="match_parent"
        android:layout_height="wrap_content" android:orientation="horizontal"
        >
    
            <LinearLayout android:layout_width="wrap_content"
                 android:layout_height="wrap_content" android:orientation="vertical"
                 android:layout_weight="1"> 
    
                <LinearLayout android:layout_width="match_parent"
                     android:layout_height="match_parent" android:orientation="horizontal">
                     <Button android:layout_width="match_parent"
                        android:layout_height="wrap_content" android:layout_weight="1"
                        android:text="1"></Button>
                     <Button android:layout_width="match_parent"
                        android:layout_height="wrap_content" android:layout_weight="1"
                        android:text="2"></Button>
                     <Button android:layout_width="match_parent"
                        android:layout_height="wrap_content" android:layout_weight="1"
                        android:text="3"></Button>
    
                </LinearLayout>  
    
                            <LinearLayout android:layout_width="match_parent"
                     android:layout_height="match_parent" android:orientation="horizontal">
                     <Button android:layout_width="match_parent"
                        android:layout_height="wrap_content" android:layout_weight="1"
                        android:text="0"></Button>
                     <Button android:layout_width="match_parent"
                        android:layout_height="wrap_content" android:layout_weight="2"
                        android:text="."></Button>
    
                </LinearLayout>
    
            </LinearLayout>    
            <LinearLayout android:layout_width="wrap_content"
                 android:layout_height="wrap_content" android:orientation="horizontal"
                 android:layout_weight="3">
                 <Button android:layout_width="match_parent"
                        android:layout_height="wrap_content" 
                        android:text="="></Button>
            </LinearLayout>         
    </LinearLayout>  
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘