自定义控件
来源:互联网 发布:知行高职英语综合教程1 编辑:程序博客网 时间:2024/06/05 06:04
XML布局
<?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:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
自定义类
package com.primecould.kala;
import com.iiordanov.bVNC.R;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
public class ImageBtn extends LinearLayout
{
private ImageView imageView;
private TextView textView;
public ImageBtn(Context paramContext)
{
super(paramContext);
}
public ImageBtn(Context paramContext, AttributeSet paramAttributeSet)
{
super(paramContext, paramAttributeSet);
((LayoutInflater)paramContext.getSystemService("layout_inflater")).inflate(R.layout.imagebtn, this);
this.imageView = ((ImageView)findViewById(R.id.imageView1));
this.textView = ((TextView)findViewById(R.id.textView1));
}
public void setImageResource(int paramInt)
{
this.imageView.setImageResource(paramInt);
}
public void setTextViewText(String paramString)
{
this.textView.setText(paramString);
}
}
引用:
this.addressBtn = ((ImageBtn)findViewById(R.id.set_image_address));
this.addressBtn.setImageResource(R.drawable.text3);
this.addressBtn.setTextViewText("平台地址");
this.addressBtn.setOnClickListener(this);
- 自定义控件
- 自定义控件
- 自定义控件
- 自定义控件
- 自定义控件
- 自定义控件
- 自定义控件
- 自定义控件
- 自定义控件
- 自定义控件
- 自定义控件
- 自定义控件
- 自定义控件
- 自定义控件
- 自定义控件
- 自定义控件
- 自定义控件
- 自定义控件
- 2016.12.30【初中部 】普及组模拟赛C组题解
- 请教一个网站显示错位的问题...
- 属性操作实例
- A1036. 分解质因数
- [我的随笔] 电脑组装
- 自定义控件
- 上传文件到服务器 杀毒
- php之汉诺塔递归算法分析和实现
- Summary of English in December
- Android Things来了
- 关于AIDL的基本要点
- FZU1062 之 洗牌问题(打表找规律)
- 大龄程序员的出路在哪里?方向
- android studio的奇怪问题