If you think the Android project android-mvc-framework listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.android_mvc.framework.ui.view;
/*fromwww.java2s.com*/import java.util.ArrayList;
import java.util.HashMap;
import com.android_mvc.framework.annotations.SuppressDebugLog;
import com.android_mvc.framework.common.FWUtil;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
/**
* LinearLayout???????????
* @author id:language_and_engineering
*
*/
@SuppressDebugLog
publicclass MLinearLayout extends LinearLayout implements IFWView
{
// ???????????????????????????????
public ArrayList<View> includingViews;
// ?????????????????View?????
privateint numInflatedViews = 0;
// NOTE: inflate????????????add?????????inflate?????????????????????????????View????????????????????????????????
// Caused by: java.lang.IllegalStateException:
// The specified child already has a parent. You must call removeView() on the child's parent first.
// ?????????????View???????????????????????????????????????????????????????????
public MLinearLayout(Context context)
{
super(context);
includingViews = new ArrayList<View>();
}
public MLinearLayout(Context context, AttributeSet attrs)
{
super(context, attrs);
includingViews = new ArrayList<View>();
}
// NOTE: ????????????????????????????????????????????????
// android.view.InflateException: Binary XML file line #?: Error inflating class ?
// @see http://q.hatena.ne.jp/1322903451
/**
* ???????????????????????????????????????
* @param v ????????View
*/public MLinearLayout add(View...v)
{
for( int i = 0; i < v.length; i ++ )
{
FWUtil.d("???????View???" + v.toString() );
this.includingViews.add( v[i] );
}
FWUtil.d("add??????????" + v.length + "????View??????");
returnthis;
}
/**
* ??????????????????????????
* ??????????????????????????????????????
* ????????????????????????????View????????????
*/publicvoid inflateInside()
{
// ?????????View????????????
for(int i = numInflatedViews; i < includingViews.size(); i ++ )
{
View v = includingViews.get(i);
//FWUtil.d("??????????View????????parentLayout = " + parentLayout.toString() + ", v = " + v.toString());
registerOneView(v);
}
// ????????View????
numInflatedViews = includingViews.size();
}
/**
* 1????????????????????????????
*/privatevoid registerOneView(View v)
{
FWUtil.d("???????????????");
// ??????View?????????????
int[] arr = getWidthHeightOfView(v);
int intWidth = arr[0];
int intHeight = arr[1];
// FW????????????????????????????????????????????????
if( v instanceof MLinearLayout )
{
FWUtil.d("FW?????????????");
MLinearLayout innerLayout = (MLinearLayout)v;
innerLayout.inflateInside();
FWUtil.d("FW????????????????????????????");
}
// ??????????????
this.addView(v, new LinearLayout.LayoutParams(intWidth, intHeight));
// http://www.javadrive.jp/android/linearlayout/index5.html
FWUtil.d("???????????????");
}
/**
* ?????View?????????????
*/privateint[] getWidthHeightOfView(View v) {
// ?????????????
int intWidth = ViewGroup.LayoutParams.WRAP_CONTENT;
int intHeight = ViewGroup.LayoutParams.WRAP_CONTENT;
// FW?????View?????????????????
if( v instanceof IFWView )
{
FWUtil.d("FW?????View??????????????");
// ???????????????
IFWView fwv = (IFWView)v;
// ??????
if( fwv.getViewParam("layout_width") != null )
{
intWidth = (Integer)fwv.getViewParam("layout_width");
}
if( fwv.getViewParam("layout_height") != null )
{
intHeight = (Integer)fwv.getViewParam("layout_height");
}
}
FWUtil.d("View????????????????????");
// ??????????
returnnewint[]{intWidth, intHeight};
}
// ?????????
HashMap<String, Object> view_params = new HashMap<String, Object>();
@Override
public Object getViewParam(String key) {
return view_params.get(key);
}
@Override
publicvoid setViewParam(String key, Object val) {
view_params.put(key, val);
}
// ??????????
public MLinearLayout orientationHorizontal() {
setOrientation(LinearLayout.HORIZONTAL);
returnthis;
}
public MLinearLayout orientationVertical() {
setOrientation(LinearLayout.VERTICAL);
returnthis;
}
public MLinearLayout widthFillParent() {
setViewParam("layout_width", ViewGroup.LayoutParams.FILL_PARENT );
returnthis;
}
public MLinearLayout heightWrapContent() {
setViewParam("layout_width", ViewGroup.LayoutParams.WRAP_CONTENT );
returnthis;
}
public MLinearLayout paddingPx( int px ) {
setPadding(px, px, px, px);
returnthis;
}
}