List of usage examples for android.widget ImageView setLayoutParams
public void setLayoutParams(ViewGroup.LayoutParams params)
From source file:com.openlocationcode.android.main.WelcomeActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); // Second argument is the default to use if the preference can't be found int savedVersionCode = prefs.getInt(WELCOME_VERSION_CODE_SHOWN_PREF, 0); int appVersionCode = 0; try {//from www . ja v a 2 s . c o m appVersionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode; } catch (NameNotFoundException nnfe) { Log.w(TAG, "Exception getting appVersionCode : " + nnfe); } final Intent intent = new Intent(this, MainActivity.class); final Activity activity = this; if (appVersionCode == savedVersionCode) { activity.startActivity(intent); activity.finish(); } else { Log.i(TAG, "Starting welcome page"); setContentView(R.layout.welcome); // Increase the margin on the image to account for the translucent status bar. ImageView welcomeImage = (ImageView) findViewById(R.id.welcome_image); LayoutParams layoutParams = (LayoutParams) welcomeImage.getLayoutParams(); layoutParams.topMargin = layoutParams.topMargin + MainActivity.getStatusBarHeight(this); welcomeImage.setLayoutParams(layoutParams); Button button = (Button) findViewById(R.id.welcome_button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { activity.startActivity(intent); activity.finish(); } }); SharedPreferences.Editor editor = prefs.edit(); editor.putInt(WELCOME_VERSION_CODE_SHOWN_PREF, appVersionCode); editor.apply(); } }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.VoiceObj.java
public void render(Context context, ViewGroup frame, Obj obj, boolean allowInteractions) { ImageView imageView = new ImageView(context); imageView.setImageResource(R.drawable.play); imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); frame.addView(imageView);/*w w w .java 2 s.co m*/ }
From source file:eu.geopaparazzi.library.forms.views.GSketchView.java
public void refresh(final Context context) throws Exception { log("Entering refresh...."); if (_value != null && _value.length() > 0) { String[] imageSplit = _value.split(";"); log("Handling images: " + _value); IImagesDbHelper imagesDbHelper = DefaultHelperClasses.getDefaulfImageHelper(); for (String imageId : imageSplit) { log("img: " + imageId); if (imageId.length() == 0) { continue; }//from w w w .j a v a 2 s .c o m long imageIdLong; try { imageIdLong = Long.parseLong(imageId); } catch (Exception e) { continue; } if (addedImages.contains(imageId.trim())) { continue; } byte[] imageThumbnail = imagesDbHelper.getImageThumbnail(imageIdLong); Bitmap thumbnail = ImageUtilities.getImageFromImageData(imageThumbnail); ImageView imageView = new ImageView(context); imageView.setLayoutParams(new LinearLayout.LayoutParams(102, 102)); imageView.setPadding(5, 5, 5, 5); imageView.setImageBitmap(thumbnail); imageView.setBackgroundDrawable(getResources().getDrawable(R.drawable.border_black_1px)); // imageView.setOnClickListener(new View.OnClickListener() { // public void onClick(View v) { // /* // * open in markers to edit it // */ // MarkersUtilities.launchOnImage(context, image); // } // }); log("Creating thumb and adding it: " + imageId); imageLayout.addView(imageView); imageLayout.invalidate(); addedImages.add(imageId); } if (addedImages.size() > 0) { StringBuilder sb = new StringBuilder(); for (String imagePath : addedImages) { sb.append(";").append(imagePath); } _value = sb.substring(1); log("New img paths: " + _value); } log("Exiting refresh...."); } }
From source file:org.zywx.wbpalmstar.plugin.uexPopoverMenu.EUExPopoverMenu.java
private void showPopoverMenu(double x, double y, int direction, String bgColorStr, String dividerColor, String textColor, int textSize, JSONArray data) { LinearLayout rootView = (LinearLayout) LayoutInflater.from(mContext) .inflate(finder.getLayoutId("plugin_uex_popovermenu"), null); final PopupWindow popupWindow = new PopupWindow(rootView, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, true); popupWindow.setContentView(rootView); ///* w ww . j a v a 2s. c o m*/ rootView.setBackgroundColor(Color.parseColor(bgColorStr)); popupWindow.setContentView(rootView); //popupWindow? popupWindow.setBackgroundDrawable(new BitmapDrawable()); popupWindow.setOutsideTouchable(true); int length = data.length(); List<ItemData> itemDataList = new ArrayList<ItemData>(); try { for (int i = 0; i < length; i++) { ItemData item = new ItemData(); String icon = data.getJSONObject(i).optString("icon", ""); if (!hasIcon && !TextUtils.isEmpty(icon)) { hasIcon = true; } if (hasIcon) { item.setIcon(data.getJSONObject(i).getString("icon")); } item.setText(data.getJSONObject(i).getString("text")); itemDataList.add(item); } } catch (JSONException e) { e.printStackTrace(); } for (int i = 0; i < length; i++) { LinearLayout linearLayout = new LinearLayout(mContext); linearLayout.setOrientation(LinearLayout.HORIZONTAL); linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); if (hasIcon) { ImageView imageView = new ImageView(mContext); imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); String imagePath = itemDataList.get(i).getIcon(); imageView.setImageBitmap(getBitmapFromPath(imagePath)); imageView.setPadding(DensityUtil.dip2px(mContext, 5), 0, 0, 0); linearLayout.addView(imageView); } TextView tvText = new TextView(mContext); LinearLayout.LayoutParams tvLayoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); tvLayoutParams.gravity = Gravity.CENTER_VERTICAL; tvText.setLayoutParams(tvLayoutParams); tvText.setPadding(DensityUtil.dip2px(mContext, 5), 0, DensityUtil.dip2px(mContext, 8), 0); tvText.setText(itemDataList.get(i).getText()); tvText.setTextColor(Color.parseColor(textColor)); tvText.setTextSize(textSize); linearLayout.addView(tvText); linearLayout.setTag(i); linearLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { callBackPluginJs(CALLBACK_ITEM_SELECTED, String.valueOf(v.getTag())); if (popupWindow != null && popupWindow.isShowing()) { popupWindow.dismiss(); } } }); rootView.addView(linearLayout); // View dividerLine = new View(mContext); dividerLine.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, DensityUtil.dip2px(mContext, 1))); dividerLine.setBackgroundColor(Color.parseColor(dividerColor)); rootView.addView(dividerLine); } int gravityParam; switch (direction) { case 0: gravityParam = Gravity.LEFT | Gravity.TOP; break; case 1: gravityParam = Gravity.RIGHT | Gravity.TOP; break; case 2: gravityParam = Gravity.LEFT | Gravity.BOTTOM; break; case 3: gravityParam = Gravity.RIGHT | Gravity.BOTTOM; break; default: gravityParam = Gravity.LEFT | Gravity.TOP; break; } popupWindow.showAtLocation(mBrwView.getRootView(), gravityParam, (int) x, (int) y); }
From source file:com.markupartist.sthlmtraveling.ui.view.SlidingTabLayout.java
/** * Create a default view to be used for tabs. This is called if a custom tab view is not set via * {@link #setCustomTabView(int, int)}.// w w w.j a va 2s .c o m */ protected ImageView createImageTabView(Context context) { ImageView v = new ImageView(context); v.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); v.setBackgroundResource(outValue.resourceId); int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); v.setPadding(padding, padding, padding, padding); return v; }
From source file:com.javielinux.utils.SplitActionBarMenu.java
private void loadActionButtons(ArrayList<String> codes, final InfoTweet infoTweet, final long ownerColumn) { main_layout.removeAllViews();/*from w w w .j av a 2 s . co m*/ boolean is_first = true; for (final String code : codes) { if (is_first) { is_first = false; } else { LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 0.0f); layoutParams.height = LinearLayout.LayoutParams.WRAP_CONTENT; layoutParams.width = LinearLayout.LayoutParams.WRAP_CONTENT; ImageView imageView = new ImageView(activity); imageView.setBackgroundResource(R.drawable.action_bar_divider); imageView.setLayoutParams(layoutParams); main_layout.addView(imageView); } final InfoSubMenuTweet infoSubMenuTweet = new InfoSubMenuTweet(activity, code); ImageButton imageButton = new ImageButton(activity); imageButton.setBackgroundResource(R.drawable.default_background); int padding = (int) activity.getResources().getDimension(R.dimen.default_padding); imageButton.setPadding(padding, padding, padding, padding); imageButton.setImageResource(infoSubMenuTweet.getResDrawable()); imageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { hideSplitActionBarMenu(); TweetActions.execByCode(code, activity, ownerColumn, infoTweet, getFromFragment()); } }); imageButton.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { Utils.showMessage(activity, activity.getResources().getString(infoSubMenuTweet.getResName())); return true; } }); main_layout.addView(imageButton); } }
From source file:com.umeng.comm.ui.emoji.EmojiBorad.java
/** * ?</br>/*from www. j av a2 s.c o m*/ * * @return */ private ImageView createIndicator() { ImageView imageView = new ImageView(getContext()); LayoutParams params = new LayoutParams(30, 30); params.gravity = Gravity.CENTER; imageView.setLayoutParams(params); imageView.setImageDrawable(ResFinder.getDrawable(mNormalIcon)); imageView.setPadding(0, 0, 10, 0); return imageView; }
From source file:org.addhen.smssync.presentation.view.ui.activity.GettingStartedActivity.java
private void renderViewPageIndicators() { float scale = getResources().getDisplayMetrics().density; int padding = (int) (5 * scale + 0.5f); for (int i = 0; i < mNumOfPages - 1; i++) { ImageView circle = new ImageView(this); circle.setImageResource(R.drawable.ic_swipe_indicator_white_18dp); circle.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); circle.setAdjustViewBounds(true); circle.setPadding(padding, 0, padding, 0); mCircles.addView(circle);//from w ww .j av a 2 s.com } setIndicator(0); }
From source file:com.birdgang.viewpagerheader.indicator.SpringIndicator.java
private void addTabItems() { LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); layoutParams.leftMargin = 30;//w ww . ja v a2 s .c o m layoutParams.rightMargin = 30; tabs = new ArrayList<>(); for (int i = 0; i < viewPager.getAdapter().getCount(); i++) { ImageView imageView = new ImageView(getContext()); imageView.setImageResource(R.drawable.btn_pop_normal); imageView.setLayoutParams(layoutParams); final int position = i; imageView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (tabClickListener == null || tabClickListener.onTabClick(position)) { viewPager.setCurrentItem(position); } } }); tabs.add(imageView); tabContainer.addView(imageView); } }
From source file:com.umeng.common.ui.emoji.EmojiBorad.java
/** * ?</br>//ww w. j a va2 s . co m * * @return */ private ImageView createIndicator() { ImageView imageView = new ImageView(getContext()); LayoutParams params = new LayoutParams(30, 30); params.gravity = Gravity.CENTER; imageView.setLayoutParams(params); imageView.setImageDrawable(ColorQueque.getDrawable(mNormalIcon)); imageView.setPadding(0, 0, 10, 0); return imageView; }