Thursday, March 31, 2016

Android Custom Compound Views

The intention is to create a compound view which actually displays a background image with 2 buttons 

This is accomplished by writing a class and subclassing it with Layout class and loading the layout xml with layout inflator.
like below. 


public class WeatherView extends LinearLayout {
    private View mValue;
    private ImageView mImage;
    
    public WeatherView(Context context, AttributeSet attrs) {
        super(context, attrs);
        setOrientation(LinearLayout.HORIZONTAL);
        setGravity(Gravity.CENTER_VERTICAL);
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.weather_view_layout, this, true);
    }
    
    public WeatherView(Context context) {
        this(context, null);
    }
    
}

The complete files with layout XML, layout subclass and Activity layout xml can be downloaded from https://drive.google.com/file/d/0B0ZgwdHsnw1baTBuNngtdGk5Rnc/view?usp=sharing


references

No comments:

Post a Comment