本文整理了Java中android.widget.ImageButton.setScaleType()
方法的一些代码示例,展示了ImageButton.setScaleType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ImageButton.setScaleType()
方法的具体详情如下:
包路径:android.widget.ImageButton
类名称:ImageButton
方法名:setScaleType
暂无
代码示例来源:origin: rockerhieu/emojicon
private void addTabIcon(EmojiconPage page, int index) {
ImageButton icon = new ImageButton(getContext());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT);
params.weight = 1;
icon.setBackground(null);
icon.setScaleType(ImageView.ScaleType.CENTER);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
icon.setImageDrawable(getContext().getResources().getDrawable(page.getIcon()));
} else {
icon.setImageDrawable(getContext().getDrawable(page.getIcon()));
}
mTabsContainer.addView(icon, mTabsContainer.getChildCount() - 2, params);
mTabs[index] = icon;
final int indexToMove = index;
icon.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mViewPager.setCurrentItem(indexToMove, true);
}
});
}
代码示例来源:origin: appnexus/mobile-sdk-android
public void run() {
Bitmap pbmp = BitmapFactory.decodeResource(adActivity.getResources(),
android.R.drawable.ic_media_play);
forward.setImageBitmap(pbmp);
Matrix x = new Matrix();
back.setScaleType(ImageView.ScaleType.MATRIX);
x.postRotate(180.0f);
Bitmap rotated = Bitmap.createBitmap(pbmp, 0, 0,
pbmp.getWidth(), pbmp.getHeight(), x, true);
back.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
forward.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
back.setImageBitmap(rotated);
}
});
代码示例来源:origin: stackoverflow.com
ImageButton topView = (ImageButton) findViewById(R.id.map_plan_topview);
Drawable d = Drawable.createFromPath(path);
topView.setScaleType(ScaleType.CENTER_CROP);
topView.setImageDrawable(d);
代码示例来源:origin: konradrenner/kolabnotes-android
public static void configureFab(View fabButton) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
fabButton.setOutlineProvider(new ViewOutlineProvider() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void getOutline(View view, Outline outline) {
int fabSize = view.getContext().getResources().getDimensionPixelSize(R.dimen.fab_size);
outline.setOval(0, 0, fabSize, fabSize);
}
});
} else {
((ImageButton) fabButton).setScaleType(ImageView.ScaleType.FIT_CENTER);
}
}
代码示例来源:origin: stackoverflow.com
private View createImageButton(int x, int y) {
ImageButton button = new ImageButton(context);
// Adjust button size (?)
button.setLayoutParams(new TableRow.LayoutParams(myImage.getMinimumWidth(),
myImage.getMinimumHeight(), 1f));
//It doesn't work at all
button.setBackground(myImage);
button.setScaleType(ScaleType.FIT_XY)
...
return button;
}
代码示例来源:origin: stackoverflow.com
ImageButton mImageButton = new ImageButton(context);
mImageButton.setImageResource(R.drawable.close_button);
RelativeLayout.LayoutParams paramsB = new RelativeLayout.LayoutParams(width, height);
paramsB.addRule(RelativeLayout.ALIGN_PARENT_TOP);
paramsB.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
mImageButton.setLayoutParams(paramsB);
mImageButton.setAdjustViewBounds(true);
mImageButton.setBackgroundDrawable(null);
mRelativeLayout.addView(mImageButton);
mImageButton.setScaleType(ImageView.ScaleType.FIT_CENTER);
代码示例来源:origin: scoutant/blokish
private ImageButton button(int src, OnClickListener l, int position) {
ImageButton btn = new ImageButton(context);
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL);
int margin = Math.min( (width - 3*128)/3, 80);
params.leftMargin = margin;
params.rightMargin = margin;
if (position==0) params.gravity = Gravity.LEFT | Gravity.CENTER_VERTICAL;
if (position==1) params.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL;
btn.setLayoutParams(params);
btn.setImageDrawable(context.getResources().getDrawable(src));
btn.setScaleType(ScaleType.CENTER_INSIDE);
btn.setBackgroundColor(Color.TRANSPARENT);
btn.setOnClickListener(l);
return btn;
}
代码示例来源:origin: devunwired/custom-touch-examples
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TwoDimensionScrollView scrollView = new TwoDimensionScrollView(this);
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
for(int i=0; i < 5; i++) {
ImageButton iv = new ImageButton(this);
iv.setImageResource(R.drawable.ic_launcher);
iv.setScaleType(ImageView.ScaleType.FIT_CENTER);
int width = getResources().getDimensionPixelSize(R.dimen.pan_content_width);
int height = getResources().getDimensionPixelSize(R.dimen.pan_content_height);
layout.addView(iv, new LinearLayout.LayoutParams(width, height));
}
scrollView.addView(layout);
setContentView(scrollView);
}
}
代码示例来源:origin: stackoverflow.com
private void addImageButton(RelativeLayout mainLayout, int x, int y, int width, int height, OnClickListener onClickListener){
ImageButton imageButton = new ImageButton(this);
imageButton.setAdjustViewBounds(true);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.height = height;
params.width = width;
imageButton.setLayoutParams(params);
imageButton.setScaleType(ImageView.ScaleType.FIT_XY);
imageButton.setImageDrawable(getResources().getDrawable(R.drawable.ic_launcher));
params.leftMargin = x - width/2;
params.topMargin = y - height/2;
imageButton.setOnClickListener(onClickListener);
mainLayout.addView(imageButton);
}
代码示例来源:origin: stackoverflow.com
imageButton = new ImageButton(mContext);
imageButton.setLayoutParams(new GridView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
imageButton.setScaleType(ImageButton.ScaleType.CENTER_CROP);
} else {
imageButton = (ImageButton) convertView;
imageButton.setScaleType(ScaleType.FIT_CENTER);
imageButton.setBackgroundResource(R.drawable.bg_button);
imageButton.setImageResource(mThumbIds[position]);
代码示例来源:origin: stackoverflow.com
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) { // if it's not recycled, initialize some
// attributes
LayoutInflater li = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = li.inflate(R.layout.icon_launcher, null);
}
TextView tv = (TextView) convertView.findViewById(R.id.icon_text);
ImageButton ib = (ImageButton) convertView.findViewById(R.id.icon_image);
LinearLayout icon = (LinearLayout) convertView
.findViewById(R.id.icon_launcher);
// icon.setLayoutParams(new GridView.LayoutParams(203,200));
ib.setScaleType(ib.getScaleType().FIT_XY);
ib.setPadding(1, 1, 1, 1);
ib.setFocusable(false);
ib.setClickable(false);
ib.setImageBitmap(BitmapFactory.decodeFile(mThumbIds.get(position)));
tv.setText(mTextsIds.get(position));
return convertView;
}
代码示例来源:origin: laizimo/richeditor
@NonNull
@Override
public ImageButton createView() {
ImageButton imageView = new ImageButton(getContext());
if(!enableAutoSet) {
TypedArray typedArray = getContext().obtainStyledAttributes(new int[]{R.attr.selectableItemBackgroundBorderless});
Drawable drawable = typedArray.getDrawable(0);
imageView.setBackgroundDrawable(drawable);
typedArray.recycle();
}else
imageView.setBackgroundDrawable(null);
imageView.setImageResource(idRes);
imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
imageView.setPadding(12, 32, 12, 32);
return imageView;
}
代码示例来源:origin: EggUncle/XposedNavigationBar
btnBack.setScaleType(ImageView.ScaleType.FIT_CENTER);
btnBack.setBackgroundColor(Color.alpha(255));
btnFunc.setScaleType(ImageView.ScaleType.FIT_CENTER);
btnFunc.setBackgroundColor(Color.alpha(255));
代码示例来源:origin: ybonnel/TransportsRennes
R.dimen.actionbar_compat_height), ViewGroup.LayoutParams.FILL_PARENT));
actionButton.setImageDrawable(icon);
actionButton.setScaleType(ImageView.ScaleType.CENTER);
actionButton.setContentDescription(title);
actionButton.setOnClickListener(clickListener);
代码示例来源:origin: wuhenzhizao/android-titlebar
btnRight.setImageResource(rightImageResource);
btnRight.setBackgroundColor(Color.TRANSPARENT);
btnRight.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
btnRight.setPadding(PADDING_12, 0, PADDING_12, 0);
btnRight.setOnClickListener(this);
代码示例来源:origin: EggUncle/XposedNavigationBar
private static void initHomeNavbar(LinearLayout homeNavbar, final ViewPager vp) {
XpLog.i("initHomeNavbar");
Context context = homeNavbar.getContext();
ImageButton btnCall = new ImageButton(context);
btnCall.setBackgroundColor(Color.RED);
btnCall.setImageBitmap(ImageUtil.byte2Bitmap(DataHook.mapImgRes.get(ConstantStr.FUNC_SMALL_POINT_CODE)));
btnCall.setScaleType(ImageView.ScaleType.FIT_CENTER);
//btnCall.setBackgroundColor(Color.alpha(255));
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
homeNavbar.addView(btnCall, params);
setHomePointPosition(homeNavbar);
btnCall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
vp.setCurrentItem(2);
}
});
}
代码示例来源:origin: stackoverflow.com
imageButton = new ImageButton(mContext);
imageButton.setLayoutParams(new GridView.LayoutParams(100, 100));
imageButton.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageButton.setPadding(0, 0, 0, 0);
imageButton.setFocusable(false);
代码示例来源:origin: stackoverflow.com
public View getView(int position, View convertView, ViewGroup parent) {
final ImageButton button;
if (convertView == null) {
button = new ImageButton(mContext);
button.setPadding(2,2,2,2);
} else {
button = (ImageButton) convertView;
}
button.setId(position);
button.setImageResource(mThumbIds[position]);
button.setScaleType(ImageButton.ScaleType.CENTER_INSIDE);
//Scale button using layout params
double parentWidth = ((MainActivity) mContext).findViewById(R.id.gridview).getWidth();
double width = button.getDrawable().getIntrinsicWidth();
double height = button.getDrawable().getIntrinsicHeight();
double scalex = parentWidth / parentWidth;
double scaley = parentWidth / width;
int newWidth = (int) (width * scalex);
int newHeight = (int) (height * scaley);
button.setLayoutParams(new GridView.LayoutParams(newWidth, newHeight));
return button;
}
代码示例来源:origin: marzika/Snapprefs
saveSnapButton = new ImageButton(localContext);
saveSnapButton.setLayoutParams(layoutParams);
saveSnapButton.setScaleType(ImageView.ScaleType.FIT_XY);
saveSnapButton.setPadding(0,0,0,0);
saveSnapButton.setAdjustViewBounds(true);
代码示例来源:origin: stackoverflow.com
btn.setScaleType(ImageView.ScaleType.CENTER_CROP);
内容来源于网络,如有侵权,请联系作者删除!