Android之自定义组合view

本文探讨如何在Android项目中创建自定义组合视图,减少重复代码。通过将系统组件如ImageView、Button等组合,实现类似ActionBar的顶部菜单栏功能。在实现过程中,详细介绍了构造函数的使用,特别是在Fragment中遇到的问题及其解决方案。
摘要由CSDN通过智能技术生成

本文主要记录一些零碎的东西

项目中发现要重复写的东西太多了,开始自己造轮子,这个自定义的view很简单,只需要几步就好了,

这里的自定义的view,只要是实现类似于actionBar的顶部菜单栏功能,使用组合控件,即使用系统提供的组件,而不是自己去绘制,把所需组件组合在一起,我的如下  

<?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="40dp"
    >
    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1">
    </LinearLayout>
    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="10"

        android:gravity="center">
        <TextView
            android:id="@+id/home_top_business"
            android:layout_width="50dp"
            android:layout_height="25dp"
            android:gravity="center"
            android:textColor="#000"
            android:background="@drawable/corners_bg"
            android:text="@string/business"/>
        <TextView
            android:id="@+id/home_top_wares"
            android:layout_width="50dp"
            android:layout_height="25dp"
            android:gravity="center"
            android:textColor="#000"
            android:background="@drawable/corners_bg"
            android:text="@string/wares"/>
        <TextView
            android:id="@&#
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值