package com.hecx.PageView;
import android.content.Context;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
/*
* 自定义复合组件
*/
public class ImageTextCompound extends LinearLayout {
private ImageView image;
private TextView text;
private final String namespace = "http://net.hecx.mobile";
/*
* AttributeSet用于从xml配置文件中读取参数
*/
public ImageTextCompound(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public ImageTextCompound(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
String infService = Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater li = (LayoutInflater) getContext().getSystemService(infService);
li.inflate(R.layout.page_item, this, true);
image = (ImageView) findViewById(R.id.page_image);
text = (TextView) findViewById(R.id.page_desc);
int imageResourceId = attrs.getAttributeResourceValue(namespace, "imageSrc", 0);
int textResourceId = attrs.getAttributeResourceValue(namespace, "textSrc", 0);
Log.v("TAG", "imageResourceId="+imageResourceId);
Log.v("TAG", "textResourceId="+textResourceId);
image.setImageResource(imageResourceId);
text.setText(textResourceId);
Log.v("TAG", text.getText().toString());
// 两个控件之间的联系
hookupViews();
}
// 两个控件之间的联系,比如增加单击一个控件时另一个控件跟着变化
private void hookupViews() {
//
}
//获取屏幕大小
private void initPx(){
DisplayMetrics dm = new DisplayMetrics();
}
}
没有评论:
发表评论