一个较为复杂的布局例子

1 目标

2 分析

  整体的框架结构想法

  

3 代码

  1 <?xml version="1.0" encoding="utf-8"?>
  2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3     android:layout_width="fill_parent"
  4     android:layout_height="wrap_content"
  5     android:orientation="vertical" >
  6 
  7     <LinearLayout android:layout_width="fill_parent"
  8         android:layout_height="wrap_content"
  9         android:orientation="horizontal">
 10         <TextView
 11             android:id="@+id/shop_name" 
 12             android:layout_width="wrap_content"
 13             android:layout_height="wrap_content"
 14             android:layout_weight="1"
 15             android:layout_marginLeft="20dp"
 16             android:textColor="@color/black"
 17             android:textSize="20dp"
 18             android:text="日照绿茶"/>
 19                     <TextView
 20                 android:id="@+id/shop_id"
 21                 android:layout_width="0dp"
 22                 android:layout_height="0dp"
 23                 android:layout_centerVertical="true"
 24                 android:layout_toRightOf="@id/shop_name"
 25                 android:visibility="gone" />
 26         <Button
 27             android:id="@+id/product_delete" 
 28             android:layout_width="50dp"
 29             android:layout_height="30dp"
 30             android:text="删除"
 31             android:textSize="15sp"
 32             android:textColor="@color/white"
 33             android:background="@drawable/gou_mai_bg"/>
 34     </LinearLayout>
 35     <LinearLayout android:layout_width="fill_parent"
 36         android:layout_height="wrap_content"
 37         android:orientation="horizontal">
 38         <LinearLayout android:layout_width="fill_parent"
 39             android:layout_height="wrap_content"
 40             android:layout_weight="1"
 41             android:layout_gravity="center_vertical"
 42             android:orientation="horizontal">
 43             <CheckBox
 44                 android:id="@+id/product_cb" 
 45                 android:layout_width="wrap_content"
 46                 android:layout_gravity="center_vertical"
 47                 android:layout_height="wrap_content"/>
 48             <ImageView
 49                 android:id="@+id/product_image" 
 50                 android:layout_width="wrap_content"
 51                 android:layout_height="wrap_content"
 52                 android:adjustViewBounds="true"
 53                 android:src="@drawable/hua"/>
 54         </LinearLayout>
 55         <LinearLayout android:layout_width="fill_parent"
 56             android:layout_height="wrap_content"
 57             android:layout_weight="1"
 58             android:orientation="vertical">
 59             <TextView
 60                 android:id="@+id/product_name" 
 61                 android:layout_width="wrap_content"
 62                 android:layout_height="wrap_content"
 63                 android:textColor="@color/black"
 64                    android:textSize="15dp"
 65                 android:text="浓香型贴关心"/>
 66             <LinearLayout android:layout_width="fill_parent"
 67                 android:layout_height="wrap_content"
 68                 android:orientation="horizontal">
 69                 <TextView
 70                     android:id="@+id/product_id" 
 71                     android:layout_width="wrap_content"
 72                 android:layout_height="wrap_content"
 73                 android:textColor="@color/black"
 74                    android:textSize="15dp"
 75                 android:text="编号:"/>
 76                 <TextView android:layout_width="wrap_content"
 77                 android:layout_height="wrap_content"
 78                 android:textColor="@color/black"
 79                    android:textSize="15dp"
 80                 android:text="11501"/>
 81             </LinearLayout>
 82             <LinearLayout android:layout_width="fill_parent"
 83                 android:layout_height="wrap_content"
 84                 android:orientation="horizontal">
 85                 <TextView android:layout_width="wrap_content"
 86                 android:layout_height="wrap_content"
 87                 android:textSize="15sp"
 88                 android:textColor="@android:color/black"
 89                 android:text="购买量:"/>
 90             <ImageButton android:id="@+id/reduce"
 91                 android:layout_width="30dp"
 92                 android:layout_gravity="center_vertical"
 93                 android:layout_height="wrap_content"
 94                 android:background="@drawable/jian_hao"/>
 95             <TextView android:layout_width="40dp"
 96                 android:layout_height="40dp"
 97                 android:text="1"
 98                 android:gravity="center"
 99                 android:textSize="15sp"
100                 android:textColor="@android:color/black"
101                 android:id="@+id/product_amount"
102                 android:background="@drawable/add_kuang"/>
103             <ImageButton android:id="@+id/add"
104                 android:layout_width="30dp"
105                 android:layout_gravity="center_vertical"
106                 android:layout_height="wrap_content"
107                 android:background="@drawable/add"/>
108             </LinearLayout>
109             <TextView 
110                 android:id="@+id/product_total_money"
111                 android:layout_width="wrap_content"
112                 android:layout_height="wrap_content"
113                 android:textSize="15sp"
114                 android:textColor="@android:color/black"
115                 android:text="800元"/>
116         </LinearLayout>
117     </LinearLayout>
118 
119 </LinearLayout>

4 实际代码实现的效果图

原文地址:https://www.cnblogs.com/YangBinChina/p/3645390.html