1. 效果图
2. 实现代码
package com.example.timetest; import android.content.Context; import android.util.AttributeSet; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; public class ImageButton extends LinearLayout { private ImageView mImageView; private TextView mTextView; public ImageButton ( Context context , AttributeSet attrs ) { super ( context , attrs ); mImageView = new ImageView ( context ); mImageView.setImageResource ( R.drawable.add_tip ); mImageView.setPadding ( 0 , 0 , 5 , 0 ); mTextView = new TextView ( context ); mTextView.setText ( "添加提醒" ); setOrientation ( LinearLayout.HORIZONTAL ); addView ( mImageView ); addView ( mTextView ); } }
3. 使用的图片
4. 使用自定义控件
<com.example.timetest.ImageButton android:id="@+id/add" android:layout_width="match_parent" android:layout_height="40dp" android:gravity="center" />
Ok 完成了
时间: 2024-11-13 09:55:19