Android记录:layout

本文详细解析了Android应用开发中常见的布局方式及属性设置,包括LinearLayout、RelativeLayout等的使用技巧,并通过实例展示了不同布局间的区别。

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

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="10dp"
        android:text="@string/first"
        android:textSize="9dp"/>
     
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/second" />
   
    <LinearLayout
        android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:orientation="vertical" >
     <TextView
         android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      android:text="@string/third"/>
     <Button
         android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      android:text="@string/third"/>
    </LinearLayout>
   
     <RelativeLayout
        android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:orientation="vertical" >
     <TextView
         android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      android:layout_alignParentLeft="true"
      android:text="@string/third"/>
     <Button
         android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      android:layout_alignParentRight="true"
      android:text="@string/third"/>
    </RelativeLayout>
    
     <RelativeLayout  
       android:layout_width="wrap_content"  
    android:layout_height="wrap_content" android:gravity="right"
     android:padding="10dp">
         <TextView
         android:id="@+id/mTextView02"
         android:layout_alignParentLeft="true"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="Case" />
     <Button
          android:id="@+id/mButton01"
          android:layout_alignParentRight="true"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="send" />
      </RelativeLayout>
      
</LinearLayout>

<!-- android:layout_width="fill_parent" 布局宽度塞满整个屏
  android:layout_width="wrap_content" 根据所在控件的宽度选择宽度-->

请用<!-- 支出类别选择图标组 --> <!-- 支出类别图标组 --> <LinearLayout android:id="@+id/expense_category_group_search_1" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginBottom="16dp"> <ImageButton android:id="@+id/category_food" android:layout_width="69dp" android:layout_height="wrap_content" app:srcCompat="@mipmap/hs_canyin_f" android:background="@color/button_default" /> <ImageButton android:id="@+id/category_shopping" android:layout_width="69dp" android:layout_height="wrap_content" android:background="@color/button_default" app:srcCompat="@mipmap/hs_gouwu_f" /> <ImageButton android:id="@+id/category_utilities" android:layout_width="69dp" android:layout_height="wrap_content" app:srcCompat="@mipmap/hs_shuidianfei_f" android:background="@color/button_default" /> <ImageButton android:id="@+id/category_phone" android:layout_width="69dp" android:layout_height="wrap_content" app:srcCompat="@mipmap/hs_tongxun_f" android:background="@color/button_default" /> <ImageButton android:id="@+id/category_entertainment" android:layout_width="69dp" android:layout_height="wrap_content" app:srcCompat="@mipmap/hs_yule_f" android:background="@color/button_default" /> </LinearLayout> <LinearLayout android:id="@+id/expense_category_group_search_2" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginBottom="16dp"> <ImageButton android:id="@+id/category_other_outcome" android:layout_width="69dp" android:layout_height="wrap_content" app:srcCompat="@mipmap/hs_qt_f" android:background="@color/button_default" /> </LinearLayout> <!-- 收入类别图标组 --> <LinearLayout android:id="@+id/income_category_group_search_1" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginBottom="16dp" android:visibility="gone"> <ImageButton android:id="@+id/category_salary" android:layout_width="69dp" android:layout_height="wrap_content" android:background="@color/button_default" app:srcCompat="@mipmap/hs_xinzi_f" /> <ImageButton android:id="@+id/category_collect_debt" android:layout_width="69dp" android:layout_height="wrap_content" android:background="@color/button_default" app:srcCompat="@mipmap/hs_shouzhai_f" /> <ImageButton android:id="@+id/category_bonus" android:layout_width="69dp" android:layout_height="wrap_content" android:background="@color/button_default" app:srcCompat="@mipmap/hs_jiangjin_f" /> <ImageButton android:id="@+id/category_investment" android:layout_width="69dp" android:layout_height="wrap_content" android:background="@color/button_default" app:srcCompat="@mipmap/hs_touzi_f" /> <ImageButton android:id="@+id/category_accident" android:layout_width="69dp" android:layout_height="wrap_content" android:background="@color/button_default" app:srcCompat="@mipmap/hs_yiwaisuode_f" /> </LinearLayout> <LinearLayout android:id="@+id/income_category_group_search_2" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginBottom="16dp" android:visibility="gone"> <ImageButton android:id="@+id/category_other_income" android:layout_width="69dp" android:layout_height="wrap_content" android:background="@color/button_default" app:srcCompat="@mipmap/hs_qita_f" /> </LinearLayout> 代替<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="16dp"> <!-- 返回按钮 --> <Button android:id="@+id/back_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="返回" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent" /> <!-- 标题 --> <TextView android:id="@+id/search_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="查询记录" android:textSize="24sp" android:textStyle="bold" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintEnd_toStartOf="@id/back_button" /> <!-- 输入金额框 --> <EditText android:id="@+id/search_input" android:layout_width="0dp" android:layout_height="wrap_content" android:hint="金额" android:inputType="numberDecimal" android:digits="0123456789." android:textSize="16sp" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toStartOf="@id/by_amount_button" app:layout_constraintTop_toBottomOf="@id/search_title" android:layout_marginTop="16dp"/> <!-- 按金额查找按钮 --> <Button android:id="@+id/by_amount_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按金额查找" app:layout_constraintStart_toEndOf="@id/search_input" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toBottomOf="@id/back_button" android:layout_marginStart="8dp"/> <!-- 收入/支出按钮 --> <Button android:id="@+id/income_button" android:layout_width="0dp" android:layout_height="wrap_content" android:text="收入明细" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toStartOf="@id/expense_button" app:layout_constraintTop_toBottomOf="@id/by_amount_button" android:layout_marginTop="16dp"/> <Button android:id="@+id/expense_button" android:layout_width="0dp" android:layout_height="wrap_content" android:text="支出明细" app:layout_constraintStart_toEndOf="@id/income_button" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toBottomOf="@id/by_amount_button" android:layout_marginTop="16dp"/> <!-- 日期选择按钮 --> <Button android:id="@+id/date_picker_button" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="选择日期" app:layout_constraintTop_toBottomOf="@id/income_button" android:layout_marginTop="16dp"/> <!-- 类别单选组:两行三列布局 --> <RadioGroup android:id="@+id/category_group" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:padding="8dp" app:layout_constraintTop_toBottomOf="@id/date_picker_button" android:layout_marginTop="16dp"> <RadioButton android:id="@+id/category_food" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="餐饮" /> <RadioButton android:id="@+id/category_shopping" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="购物" /> <RadioButton android:id="@+id/category_utilities" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="水电" /> <RadioButton android:id="@+id/category_phone" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="话费" /> <RadioButton android:id="@+id/category_entertainment" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="娱乐" /> <RadioButton android:id="@+id/category_other" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="其他" /> </RadioGroup> <!-- 查询结果表格 --> <ScrollView android:layout_width="match_parent" android:layout_height="0dp" app:layout_constraintTop_toBottomOf="@id/category_group" app:layout_constraintBottom_toBottomOf="parent" android:layout_marginTop="16dp"> <TableLayout android:id="@+id/result_table" android:layout_width="match_parent" android:layout_height="wrap_content" android:stretchColumns="*" /> </ScrollView> </androidx.constraintlayout.widget.ConstraintLayout> 的radiogroup部分
最新发布
06-28
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值