【Android-布局复用】 多个界面复用一个布局文件(一)

本文介绍了如何在Android开发中实现布局复用,通过创建`layout_common.xml`作为复用布局文件,然后在`layout_main.xml`主布局中引用。此外,还详细讲解了`CommonView.java`类,它是复用布局的实例化并实现了接口回调,以减少重复代码。最后,在`MainActivity.java`中展示了如何在实际应用中实例化和使用这些复用布局。
摘要由CSDN通过智能技术生成

1.layout_common.xml

复用的布局文件

<?xml version="1.0" encoding="utf-8"?>
<!-- 复用的布局文件 -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1" />

    <Button
        android:id="@+id/common_button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="按钮1" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1" />

    <Button
        android:id="@+id/common_button2"
        android:layout_width="wrap_content"
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值