• 15.Android中LinearLayout布局一些小记录


    在App中,我们经常看到布局中会有分割线,直接上代码:

     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="vertical">
     6 
     7     <Button
     8         android:id="@+id/button1"
     9         android:layout_width="wrap_content"
    10         android:layout_height="wrap_content"
    11         android:text="btn1" />
    12     
    13     <ImageView   
    14         android:layout_width="fill_parent"  
    15         android:layout_height="2dp"  
    16         android:background="#e5e5e5"  
    17         />  
    18 
    19     <Button
    20         android:id="@+id/button2"
    21         android:layout_width="wrap_content"
    22         android:layout_height="wrap_content"
    23         android:text="btn2" />
    24     
    25    <LinearLayout
    26         android:orientation="vertical"
    27         android:layout_width="match_parent"
    28         android:layout_height="0.5dp"
    29         android:background="#e5e5e5">
    30     </LinearLayout>
    31     
    32 
    33     <Button
    34         android:id="@+id/button3"
    35         android:layout_width="wrap_content"
    36         android:layout_height="wrap_content"
    37         android:text="btn3" />
    38     
    39      <View
    40         android:layout_width="fill_parent"
    41         android:layout_height="0.5dp"
    42         android:background="#e5e5e5"/> 
    43 
    44 </LinearLayout>

    运行效果:

       

      实现方法主要放置一个ImageView、View或者LinearLayout组件,然后将其设为分隔线的颜色即可。

    同理我们可以通过利用view来设置分开两边部件,代码如下:

     1 <LinearLayout
     2             android:orientation="horizontal"
     3             android:layout_width="match_parent"
     4             android:layout_height="wrap_content">
     5 
     6             <TextView
     7                 android:layout_width="wrap_content"
     8                 android:layout_height="60dp"
     9                 android:layout_marginLeft="15dp"
    10                 android:gravity="center"
    11                 android:text="textview1"
    12                 android:id="@+id/"textview1""/>
    13 
    14             <View
    15                 android:layout_width="0dp"
    16                 android:layout_weight="1"
    17                 android:layout_height="match_parent"/>
    18 
    19 
    20             <TextView
    21                 android:layout_width="wrap_content"
    22                 android:layout_height="60dp"
    23                 android:layout_marginRight="15dp"
    24                 android:gravity="center"
    25                 android:text="textview2"
    26                 android:id="@+id/textview2"/>
    27 
    28         </LinearLayout>

    效果如图:

  • 相关阅读:
    个人阅读作业+个人总结
    个人作业Week3-案例分析
    个人作业Week2-代码复审
    个人作业-Week1
    个人项目-数独
    第0次个人作业
    团队项目-游戏引擎的考察
    Week3结对项目-数独游戏
    个人作业Week3-案例分析
    代码复审
  • 原文地址:https://www.cnblogs.com/benchao/p/5083344.html
Copyright © 2020-2023  润新知