下面列出了android.widget.HorizontalScrollView#setLayoutParams ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private LinearLayout getPlatformList() {
LinearLayout llToolBar = new LinearLayout(getContext());
LinearLayout.LayoutParams lpTb = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
llToolBar.setLayoutParams(lpTb);
TextView tvShareTo = new TextView(getContext());
int resId = getStringRes(activity, "share_to");
if (resId > 0) {
tvShareTo.setText(resId);
}
tvShareTo.setTextColor(0xffcfcfcf);
tvShareTo.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
int dp_9 = dipToPx(getContext(), 9);
LinearLayout.LayoutParams lpShareTo = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lpShareTo.gravity = Gravity.CENTER_VERTICAL;
lpShareTo.setMargins(dp_9, 0, 0, 0);
tvShareTo.setLayoutParams(lpShareTo);
llToolBar.addView(tvShareTo);
HorizontalScrollView sv = new HorizontalScrollView(getContext());
sv.setHorizontalScrollBarEnabled(false);
sv.setHorizontalFadingEdgeEnabled(false);
LinearLayout.LayoutParams lpSv = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lpSv.setMargins(dp_9, dp_9, dp_9, dp_9);
sv.setLayoutParams(lpSv);
llToolBar.addView(sv);
llPlat = new LinearLayout(getContext());
llPlat.setLayoutParams(new HorizontalScrollView.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
sv.addView(llPlat);
return llToolBar;
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mRootLayout = new HorizontalScrollView(getContext());
mRootLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
mParentLayout = new LinearLayout(getContext());
mParentLayout.setOrientation(LinearLayout.HORIZONTAL);
mScroller = new Scroller(mRootLayout.getContext(), new DecelerateInterpolator(1.2f));
mParentLayout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
mRootLayout.addView(mParentLayout);
addView(mRootLayout);
SetColumnSnap(true);
}
private LinearLayout getPlatformList() {
LinearLayout llToolBar = new LinearLayout(getContext());
LayoutParams lpTb = new LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
llToolBar.setLayoutParams(lpTb);
TextView tvShareTo = new TextView(getContext());
int resId = getStringRes(activity, "share_to");
if (resId > 0) {
tvShareTo.setText(resId);
}
tvShareTo.setTextColor(0xffcfcfcf);
tvShareTo.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
int dp_9 = dipToPx(getContext(), 9);
LayoutParams lpShareTo = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lpShareTo.gravity = Gravity.CENTER_VERTICAL;
lpShareTo.setMargins(dp_9, 0, 0, 0);
tvShareTo.setLayoutParams(lpShareTo);
llToolBar.addView(tvShareTo);
HorizontalScrollView sv = new HorizontalScrollView(getContext());
sv.setHorizontalScrollBarEnabled(false);
sv.setHorizontalFadingEdgeEnabled(false);
LayoutParams lpSv = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lpSv.setMargins(dp_9, dp_9, dp_9, dp_9);
sv.setLayoutParams(lpSv);
llToolBar.addView(sv);
llPlat = new LinearLayout(getContext());
llPlat.setLayoutParams(new HorizontalScrollView.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
sv.addView(llPlat);
return llToolBar;
}
private LinearLayout getPlatformList() {
LinearLayout llToolBar = new LinearLayout(getContext());
LayoutParams lpTb = new LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
llToolBar.setLayoutParams(lpTb);
TextView tvShareTo = new TextView(getContext());
int resId = getStringRes(activity, "share_to");
if (resId > 0) {
tvShareTo.setText(resId);
}
tvShareTo.setTextColor(0xffcfcfcf);
tvShareTo.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
int dp_9 = dipToPx(getContext(), 9);
LayoutParams lpShareTo = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lpShareTo.gravity = Gravity.CENTER_VERTICAL;
lpShareTo.setMargins(dp_9, 0, 0, 0);
tvShareTo.setLayoutParams(lpShareTo);
llToolBar.addView(tvShareTo);
HorizontalScrollView sv = new HorizontalScrollView(getContext());
sv.setHorizontalScrollBarEnabled(false);
sv.setHorizontalFadingEdgeEnabled(false);
LayoutParams lpSv = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lpSv.setMargins(dp_9, dp_9, dp_9, dp_9);
sv.setLayoutParams(lpSv);
llToolBar.addView(sv);
llPlat = new LinearLayout(getContext());
llPlat.setLayoutParams(new HorizontalScrollView.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
sv.addView(llPlat);
return llToolBar;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
context = this;
textSize = (int) getResources().getDimension(R.dimen.cell_text_size);
padding = (int) getResources().getDimension(R.dimen.cell_padding);
Nosey nosey = Nosey.getInstance(this);
Inspector.ModelMapInspector inspector = new Inspector.ModelMapInspector();
inspector.inspect(nosey);
String modelKey = getIntent().getStringExtra(EXTRA_MODEL_KEY);
model = inspector.getModelMap().get(modelKey);
methods = model.getDeclaredMethods();
Arrays.sort(methods, new MemberComparator<Method>());
TableLayout table = new TableLayout(this);
addModelFieldHeaders(table, inspector);
addModelDataRows(table, inspector);
ScrollView scrollView = new ScrollView(this);
scrollView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
scrollView.setHorizontalScrollBarEnabled(true);
scrollView.setVerticalScrollBarEnabled(true);
scrollView.setFillViewport(true);
HorizontalScrollView horizontalScrollView = new HorizontalScrollView(this);
horizontalScrollView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
horizontalScrollView.setHorizontalScrollBarEnabled(true);
horizontalScrollView.setVerticalScrollBarEnabled(true);
horizontalScrollView.setFillViewport(true);
scrollView.addView(horizontalScrollView);
horizontalScrollView.addView(table);
setContentView(scrollView);
}
private LinearLayout getPlatformList() {
LinearLayout llToolBar = new LinearLayout(getContext());
LinearLayout.LayoutParams lpTb = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
llToolBar.setLayoutParams(lpTb);
TextView tvShareTo = new TextView(getContext());
int resId = getStringRes(activity, "share_to");
if (resId > 0) {
tvShareTo.setText(resId);
}
tvShareTo.setTextColor(0xffcfcfcf);
tvShareTo.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
int dp_9 = dipToPx(getContext(), 9);
LinearLayout.LayoutParams lpShareTo = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lpShareTo.gravity = Gravity.CENTER_VERTICAL;
lpShareTo.setMargins(dp_9, 0, 0, 0);
tvShareTo.setLayoutParams(lpShareTo);
llToolBar.addView(tvShareTo);
HorizontalScrollView sv = new HorizontalScrollView(getContext());
sv.setHorizontalScrollBarEnabled(false);
sv.setHorizontalFadingEdgeEnabled(false);
LinearLayout.LayoutParams lpSv = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lpSv.setMargins(dp_9, dp_9, dp_9, dp_9);
sv.setLayoutParams(lpSv);
llToolBar.addView(sv);
llPlat = new LinearLayout(getContext());
llPlat.setLayoutParams(new HorizontalScrollView.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
sv.addView(llPlat);
return llToolBar;
}
private LinearLayout getPlatformList() {
LinearLayout llToolBar = new LinearLayout(getContext());
LinearLayout.LayoutParams lpTb = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
llToolBar.setLayoutParams(lpTb);
TextView tvShareTo = new TextView(getContext());
int resId = getStringRes(activity, "share_to");
if (resId > 0) {
tvShareTo.setText(resId);
}
tvShareTo.setTextColor(0xffcfcfcf);
tvShareTo.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
int dp_9 = dipToPx(getContext(), 9);
LinearLayout.LayoutParams lpShareTo = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lpShareTo.gravity = Gravity.CENTER_VERTICAL;
lpShareTo.setMargins(dp_9, 0, 0, 0);
tvShareTo.setLayoutParams(lpShareTo);
llToolBar.addView(tvShareTo);
HorizontalScrollView sv = new HorizontalScrollView(getContext());
sv.setHorizontalScrollBarEnabled(false);
sv.setHorizontalFadingEdgeEnabled(false);
LinearLayout.LayoutParams lpSv = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lpSv.setMargins(dp_9, dp_9, dp_9, dp_9);
sv.setLayoutParams(lpSv);
llToolBar.addView(sv);
llPlat = new LinearLayout(getContext());
llPlat.setLayoutParams(new HorizontalScrollView.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
sv.addView(llPlat);
return llToolBar;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
context = this;
textSize = (int) getResources().getDimension(R.dimen.cell_text_size);
padding = (int) getResources().getDimension(R.dimen.cell_padding);
Nosey nosey = Nosey.getInstance(this);
Inspector.ModelMapInspector inspector = new Inspector.ModelMapInspector();
inspector.inspect(nosey);
String modelKey = getIntent().getStringExtra(EXTRA_MODEL_KEY);
model = inspector.getModelMap().get(modelKey);
methods = model.getDeclaredMethods();
Arrays.sort(methods, new MemberComparator<Method>());
TableLayout table = new TableLayout(this);
addModelFieldHeaders(table, inspector);
addModelDataRows(table, inspector);
ScrollView scrollView = new ScrollView(this);
scrollView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
scrollView.setHorizontalScrollBarEnabled(true);
scrollView.setVerticalScrollBarEnabled(true);
scrollView.setFillViewport(true);
HorizontalScrollView horizontalScrollView = new HorizontalScrollView(this);
horizontalScrollView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
horizontalScrollView.setHorizontalScrollBarEnabled(true);
horizontalScrollView.setVerticalScrollBarEnabled(true);
horizontalScrollView.setFillViewport(true);
scrollView.addView(horizontalScrollView);
horizontalScrollView.addView(table);
setContentView(scrollView);
}
private LinearLayout getPlatformList() {
LinearLayout llToolBar = new LinearLayout(getContext());
LinearLayout.LayoutParams lpTb = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
llToolBar.setLayoutParams(lpTb);
TextView tvShareTo = new TextView(getContext());
int resId = getStringRes(activity, "share_to");
if (resId > 0) {
tvShareTo.setText(resId);
}
tvShareTo.setTextColor(0xffcfcfcf);
tvShareTo.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
int dp_9 = dipToPx(getContext(), 9);
LinearLayout.LayoutParams lpShareTo = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lpShareTo.gravity = Gravity.CENTER_VERTICAL;
lpShareTo.setMargins(dp_9, 0, 0, 0);
tvShareTo.setLayoutParams(lpShareTo);
llToolBar.addView(tvShareTo);
HorizontalScrollView sv = new HorizontalScrollView(getContext());
sv.setHorizontalScrollBarEnabled(false);
sv.setHorizontalFadingEdgeEnabled(false);
LinearLayout.LayoutParams lpSv = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lpSv.setMargins(dp_9, dp_9, dp_9, dp_9);
sv.setLayoutParams(lpSv);
llToolBar.addView(sv);
llPlat = new LinearLayout(getContext());
llPlat.setLayoutParams(new HorizontalScrollView.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
sv.addView(llPlat);
return llToolBar;
}
/**
* Custom methods
*/
public void init(Context context, AttributeSet attributeSet) {
//Setup defaults
mContext = context;
mMaxPictures = DEFAULT_MAX_PICTURES;
mThumbnailHeight = mContext.getResources().getDimension(R.dimen.patio_default_thumbnail_height);
mThumbnailWidth = mContext.getResources().getDimension(R.dimen.patio_default_thumbnail_width);
mThumbnailsMessageString = mContext.getResources().getString(R.string.patio_thumbnails_message);
mPatioThumbnails = new ArrayList<PatioThumbnail>();
setOrientation(VERTICAL);
//Local defaults
float thumbnailsContainerPadding = mContext.getResources().getDimension(R.dimen.patio_default_thumbnails_container_padding);
int actionsTextColor = mContext.getResources().getColor(R.color.patio_default_action_text_color);
int thumbnailsWrapperBackground = mContext.getResources().getColor(R.color.patio_default_thumbnails_container_background);
//Inflate view and setup controls
LayoutInflater inflater = LayoutInflater.from(context);
inflater.inflate(WIDGET_LAYOUT_RES_ID, this, true);
//Buttons
mTakePicture = (Button) findViewById(R.id.patio_action_take_picture);
mAttachPicture = (Button) findViewById(R.id.patio_action_attach_picture);
mRemovePicture = (Button) findViewById(R.id.patio_action_remove_picture);
mCancel = (Button) findViewById(R.id.patio_action_cancel);
//Containers
mThumbnailsWrapper = (HorizontalScrollView) findViewById(R.id.patio_thumbnails_wrapper);
mThumbnailsContainer = (LinearLayout) findViewById(R.id.patio_thumbnails_container);
mThumbnailsCount = (TextView) findViewById(R.id.patio_thumbnails_count_message);
//Toolbars
mToolbarAddActions = (LinearLayout) findViewById(R.id.patio_add_actions_toolbar);
mToolbarRemoveActions = (LinearLayout) findViewById(R.id.patio_remove_actions_toolbar);
mToolbarRemoveActions.setVisibility(View.GONE);
//Set actions listeners
if(!isInEditMode()) {
mTakePicture.setOnClickListener(this);
mAttachPicture.setOnClickListener(this);
mRemovePicture.setOnClickListener(this);
mCancel.setOnClickListener(this);
}
//Get defined attributes
if(attributeSet != null) {
TypedArray a = mContext.getTheme().obtainStyledAttributes(attributeSet, R.styleable.Patio, 0, 0);
try {
//Runtime
mMaxPictures = a.getInt(R.styleable.Patio_maxPictures, DEFAULT_MAX_PICTURES);
mThumbnailHeight = a.getDimension(R.styleable.Patio_thumbnailHeight, mThumbnailHeight);
mThumbnailWidth = a.getDimension(R.styleable.Patio_thumbnailWidth, mThumbnailWidth);
mThumbnailsMessageString = a.getString(R.styleable.Patio_thumbnailsMessage);
//Local
thumbnailsContainerPadding = a.getDimension(R.styleable.Patio_thumbnailsContainerPadding, thumbnailsContainerPadding);
actionsTextColor = a.getColor(R.styleable.Patio_actionsTextColor, actionsTextColor);
thumbnailsWrapperBackground = a.getColor(R.styleable.Patio_thumbnailsContainerBackground, thumbnailsWrapperBackground);
} finally {
a.recycle();
}
}
//Check Max Pictures
if(mMaxPictures <= 0) {
mMaxPictures = DEFAULT_MAX_PICTURES;
}
//Check Thumbnail Message
if(mThumbnailsMessageString == null) {
mThumbnailsMessageString = mContext.getResources().getString(R.string.patio_thumbnails_message);
}
//Setup actions text color
mTakePicture.setTextColor(actionsTextColor);
mAttachPicture.setTextColor(actionsTextColor);
mRemovePicture.setTextColor(actionsTextColor);
mCancel.setTextColor(actionsTextColor);
//Setup thumbnails container background
mThumbnailsWrapper.setBackgroundColor(thumbnailsWrapperBackground);
//Setup dimensions
ViewGroup.LayoutParams layoutParams;
int paddingTop, paddingBottom, paddingLeft, paddingRight;
//Thumbnails Wrapper height
layoutParams = mThumbnailsWrapper.getLayoutParams();
layoutParams.height = Float.valueOf(mThumbnailHeight).intValue();
mThumbnailsWrapper.setLayoutParams(layoutParams);
//Thumbnails Container padding
paddingTop = paddingBottom = paddingLeft = paddingRight = Float.valueOf(thumbnailsContainerPadding).intValue();
mThumbnailsContainer.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
//Init Thumbnails Message
updateThumbnailsMessage();
}
/**
* Custom methods
*/
public void init(Context context, AttributeSet attributeSet) {
//Setup defaults
mContext = context;
mMaxPictures = DEFAULT_MAX_PICTURES;
mThumbnailHeight = mContext.getResources().getDimension(R.dimen.patio_default_thumbnail_height);
mThumbnailWidth = mContext.getResources().getDimension(R.dimen.patio_default_thumbnail_width);
mThumbnailsMessageString = "patio_thumbnails_message";
mPatioThumbnails = new ArrayList<PatioThumbnail>();
setOrientation(VERTICAL);
//Local defaults
float thumbnailsContainerPadding = mContext.getResources().getDimension(R.dimen.patio_default_thumbnails_container_padding);
int actionsTextColor = mContext.getResources().getColor(R.color.patio_default_action_text_color);
int thumbnailsWrapperBackground = mContext.getResources().getColor(R.color.patio_default_thumbnails_container_background);
//Inflate view and setup controls
LayoutInflater inflater = LayoutInflater.from(context);
inflater.inflate(WIDGET_LAYOUT_RES_ID, this, true);
//Buttons
mTakePicture = (Button) findViewById(R.id.patio_action_take_picture);
mAttachPicture = (Button) findViewById(R.id.patio_action_attach_picture);
mRemovePicture = (Button) findViewById(R.id.patio_action_remove_picture);
mCancel = (Button) findViewById(R.id.patio_action_cancel);
//Containers
mThumbnailsWrapper = (HorizontalScrollView) findViewById(R.id.patio_thumbnails_wrapper);
mThumbnailsContainer = (LinearLayout) findViewById(R.id.patio_thumbnails_container);
mThumbnailsCount = (TextView) findViewById(R.id.patio_thumbnails_count_message);
//Toolbars
mToolbarAddActions = (LinearLayout) findViewById(R.id.patio_add_actions_toolbar);
mToolbarRemoveActions = (LinearLayout) findViewById(R.id.patio_remove_actions_toolbar);
mToolbarRemoveActions.setVisibility(View.GONE);
//Set actions listeners
if(!isInEditMode()) {
mTakePicture.setOnClickListener(this);
mAttachPicture.setOnClickListener(this);
mRemovePicture.setOnClickListener(this);
mCancel.setOnClickListener(this);
}
//Get defined attributes
if(attributeSet != null) {
TypedArray a = mContext.getTheme().obtainStyledAttributes(attributeSet, R.styleable.Patio, 0, 0);
try {
//Runtime
mMaxPictures = a.getInt(R.styleable.Patio_patio_maxPictures, DEFAULT_MAX_PICTURES);
mThumbnailHeight = a.getDimension(R.styleable.Patio_patio_thumbnailHeight, mThumbnailHeight);
mThumbnailWidth = a.getDimension(R.styleable.Patio_patio_thumbnailWidth, mThumbnailWidth);
mThumbnailsMessageString = a.getString(R.styleable.Patio_patio_thumbnailsMessage);
//Local
thumbnailsContainerPadding = a.getDimension(R.styleable.Patio_patio_thumbnailsContainerPadding, thumbnailsContainerPadding);
actionsTextColor = a.getColor(R.styleable.Patio_patio_actionsTextColor, actionsTextColor);
thumbnailsWrapperBackground = a.getColor(R.styleable.Patio_patio_thumbnailsContainerBackground, thumbnailsWrapperBackground);
} finally {
a.recycle();
}
}
//Check Max Pictures
if(mMaxPictures <= 0) {
mMaxPictures = DEFAULT_MAX_PICTURES;
}
//Check Thumbnail Message
if(mThumbnailsMessageString == null) {
mThumbnailsMessageString = "patio_thumbnails_message";
}
//Setup actions text color
mTakePicture.setTextColor(actionsTextColor);
mAttachPicture.setTextColor(actionsTextColor);
mRemovePicture.setTextColor(actionsTextColor);
mCancel.setTextColor(actionsTextColor);
//Setup thumbnails container background
mThumbnailsWrapper.setBackgroundColor(thumbnailsWrapperBackground);
//Setup dimensions
ViewGroup.LayoutParams layoutParams;
int paddingTop, paddingBottom, paddingLeft, paddingRight;
//Thumbnails Wrapper height
layoutParams = mThumbnailsWrapper.getLayoutParams();
layoutParams.height = Float.valueOf(mThumbnailHeight).intValue();
mThumbnailsWrapper.setLayoutParams(layoutParams);
//Thumbnails Container padding
paddingTop = paddingBottom = paddingLeft = paddingRight = Float.valueOf(thumbnailsContainerPadding).intValue();
mThumbnailsContainer.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
//Init Thumbnails Message
updateThumbnailsMessage();
}