private LinearLayout getMainBody() { LinearLayout llMainBody = new LinearLayout(getContext()); llMainBody.setOrientation(LinearLayout.VERTICAL); LayoutParams lpMain = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); lpMain.weight = 1; int dp_4 = dipToPx(getContext(), 4); lpMain.setMargins(dp_4, dp_4, dp_4, dp_4); llMainBody.setLayoutParams(lpMain); LinearLayout llContent = new LinearLayout(getContext()); LayoutParams lpContent = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); lpContent.weight = 1; llMainBody.addView(llContent, lpContent); // share content editor etContent = new EditText(getContext()); etContent.setGravity(Gravity.LEFT | Gravity.TOP); etContent.setBackgroundDrawable(null); etContent.setText(String.valueOf(shareParamMap.get("text"))); etContent.addTextChangedListener(this); LayoutParams lpEt = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lpEt.weight = 1; etContent.setLayoutParams(lpEt); llContent.addView(etContent); llContent.addView(getThumbView()); llMainBody.addView(getBodyBottom()); return llMainBody; }
private void initLettersRows(final View view) { int max = getScreenMaxHeight(); DisplayMetrics displayMetrics = getActivity().getResources().getDisplayMetrics(); int dpMax = (int) ((max / displayMetrics.density) + 0.5); if (dpMax > 480) { LinearLayout lastNumbersContainer = (LinearLayout) view.findViewById(R.id.housenumber_container); LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) lastNumbersContainer.getLayoutParams(); // Changes the height and width to the specified *pixels* params.height = params.height * 3 / 2; lastNumbersContainer.setLayoutParams(params); textlastHouseNumbers3.setVisibility(View.VISIBLE); FrameLayout.LayoutParams number2Params = (FrameLayout.LayoutParams) textlastHouseNumbers2.getLayoutParams(); number2Params.gravity = Gravity.CENTER_VERTICAL; } else { textlastHouseNumbers3.setVisibility(View.GONE); } if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE || dpMax >= 580) { // do nothing } else if (dpMax > 480) { // remove one line // view.findViewById(R.id.keysRow3).setVisibility(View.GONE); ((Button) view.findViewById(R.id.buttonJ)).setText(localizer.getString("buttonSep1")); ((Button) view.findViewById(R.id.buttonK)).setText(localizer.getString("buttonSep2")); ((Button) view.findViewById(R.id.buttonL)).setText(localizer.getString("buttonSep3")); } else { // remove two lines view.findViewById(R.id.keysRow2).setVisibility(View.GONE); view.findViewById(R.id.keysRow3).setVisibility(View.GONE); ((Button) view.findViewById(R.id.buttonD)).setText(localizer.getString("buttonSep1")); ((Button) view.findViewById(R.id.buttonE)).setText(localizer.getString("buttonSep2")); ((Button) view.findViewById(R.id.buttonF)).setText(localizer.getString("buttonSep3")); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { View lfrRow = view.findViewById(R.id.lfrRow); LayoutParams params = (LayoutParams) lfrRow.getLayoutParams(); if (KeypadMapperApplication.getInstance().getSettings().isLayoutOptimizationEnabled()) { params.weight = 1.55f; } else { params.weight = 1.4f; } lfrRow.setLayoutParams(params); } } }
// if platform selected form platform gridview is SinaWeibo, // TencentWeibo, Facebook, or Twitter, there will be a button // in the left-bottom of the page, which provides At-friends function private LinearLayout getAtLine(String platform) { if (!isShowAtUserLayout(platform)) { return null; } LinearLayout llAt = new LinearLayout(getContext()); LayoutParams lpAt = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lpAt.rightMargin = dipToPx(getContext(), 4); lpAt.gravity = Gravity.LEFT | Gravity.BOTTOM; lpAt.weight = 1; llAt.setLayoutParams(lpAt); llAt.setOnClickListener( new OnClickListener() { public void onClick(View v) { if (platforms != null && platforms.size() > 0) { FollowListPage subPage = new FollowListPage(); subPage.setPlatform(platforms.get(0)); subPage.showForResult(activity, null, EditPage.this); } else { int resId = getStringRes(activity, "ssdk_oks_select_one_plat_at_least"); if (resId > 0) { Toast.makeText(getContext(), resId, Toast.LENGTH_SHORT).show(); } } } }); TextView tvAt = new TextView(getContext()); int resId = getBitmapRes(activity, "ssdk_oks_btn_back_nor"); if (resId > 0) { tvAt.setBackgroundResource(resId); } int dp_32 = dipToPx(getContext(), 32); tvAt.setLayoutParams(new LayoutParams(dp_32, dp_32)); tvAt.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); tvAt.setText(getAtUserButtonText(platform)); int dp_2 = dipToPx(getContext(), 2); tvAt.setPadding(0, 0, 0, dp_2); tvAt.setTypeface(Typeface.DEFAULT_BOLD); tvAt.setTextColor(0xff000000); tvAt.setGravity(Gravity.CENTER); llAt.addView(tvAt); TextView tvName = new TextView(getContext()); tvName.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); tvName.setTextColor(0xff000000); resId = getStringRes(activity, "ssdk_oks_list_friends"); String text = getContext().getString(resId, getName(platform)); tvName.setText(text); LayoutParams lpName = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lpName.gravity = Gravity.CENTER_VERTICAL; tvName.setLayoutParams(lpName); llAt.addView(tvName); return llAt; }
private RelativeLayout createImage(String path, int id, final String bigPath) { RelativeLayout relativeLayout = new RelativeLayout(context); LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); layoutParams.gravity = Gravity.CENTER; layoutParams.leftMargin = width / 55; layoutParams.weight = 1; relativeLayout.setLayoutParams(layoutParams); ImageView imageView = new ImageView(context); imageView.setId(id); imageView.setOnLongClickListener(this); imageView.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // 展示大图片 BigImageActivity.setViewData(bigPath); startActivity(new Intent(CaseTestActivity.this, BigImageActivity.class)); } }); LayoutParams imageViewParams = new LayoutParams(width / 15 * 4, width / 15 * 4); imageView.setLayoutParams(imageViewParams); imageView.setScaleType(ScaleType.CENTER_CROP); if (!"null".equals(path) && !"".equals(path)) { if (path.startsWith("http:")) { imageView.setTag(path); imageView.setImageResource(R.anim.loading_anim_test); ImageListener listener = ImageLoader.getImageListener(imageView, 0, android.R.drawable.ic_menu_delete); mImageLoader.get(path, listener, 200, 200); } else { Bitmap bitmap = CommonUtil.readBitMap(200, path); imageView.setImageBitmap(bitmap); } } relativeLayout.addView(imageView); return relativeLayout; }
private void initGridView() { // 上传图片 repairPicGv = (MyGridView) findViewById(R.id.repair_grid_view); repairTxtNum = (TextView) findViewById(R.id.img_txt_num); // 空数据提示 View empty = LayoutInflater.from(this).inflate(R.layout.home_circles_post_pick, null); empty.setVisibility(View.GONE); LayoutParams params = new LayoutParams(0, LayoutParams.MATCH_PARENT); params.weight = 1; ((ViewGroup) repairPicGv.getParent()).addView(empty, 0, params); repairPicGv.setEmptyView(empty); empty.setOnClickListener(this); if (imgList == null) { imgList = new ArrayList<ImgPicker>(PICK_MAX); } adapter = new CirclesPostAdapter(this, imgList, this); repairPicGv.setAdapter(adapter); repairPicGv.setOnItemClickListener(this); // radioGroup = (RadioGroup) findViewById(R.id.radio_group); }
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); int margin = Utils.dpToPx(0.02f * Utils.getDisplayMetrics().widthPixels); SpannableStringBuilder prettyMessage = new SpannableStringBuilder(message); int italicsFrom = message.indexOf(italicsString), italicsTo = italicsFrom + italicsString.length(); prettyMessage.setSpan( new StyleSpan(Typeface.ITALIC), italicsFrom, italicsTo, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); this.layout = new LinearLayout(this); this.layout.setOrientation(Orientation.VERTICAL); this.setContentView(this.layout); ScrollView sv = new ScrollView(this); LayoutParams scrollParams = new LayoutParams(LayoutParams.MATCH_PARENT, 0); scrollParams.weight = 1; // this.layout.addView(sv, scrollParams); LinearLayout innerLayout = new LinearLayout(this); innerLayout.setOrientation(Orientation.VERTICAL); LayoutParams ilParams = new LayoutParams(LayoutParams.MATCH_PARENT, 0); ilParams.weight = 1; sv.addView(innerLayout, ilParams); this.messageText = new TextView(this); messageText.setText(prettyMessage); messageText.setTextSize(14); messageText.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL); LayoutParams textParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); textParams.weight = 0; textParams.gravity = Gravity.LEFT | Gravity.CENTER_VERTICAL; textParams.setMargins(margin, margin, margin, margin / 2); this.layout.addView(messageText, textParams); final EditText sender = new EditText(this); sender.setInputType(InputType.TYPE_CLASS_TEXT); sender.setHint("Je e-mailadres (als je iets terug wilt horen)"); LayoutParams senderParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); senderParams.weight = 0; senderParams.setMargins(margin, 0, margin, 0); this.layout.addView(sender, senderParams); final EditText detail = new EditText(this); detail.setHint("Wat wil je zeggen?"); detail.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE); detail.setGravity(Gravity.TOP); LayoutParams detailParams = new LayoutParams(LayoutParams.MATCH_PARENT, 0); detailParams.weight = 0.5f; detailParams.setMargins(margin, 0, margin, 0); this.layout.addView(detail, detailParams); loading = new ProgressBar(activity); loading.setIndeterminate(true); submit = new Button(this); submit.setText("Versturen"); submitParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); submitParams.weight = 0; submitParams.setMargins(0, 0, 0, margin); submitParams.gravity = Gravity.CENTER; submit.setOnClickListener( new OnClickListener() { public void onClick(View v) { activity.hideOnScreenKeyboard(sender.getWindowToken()); activity.hideOnScreenKeyboard(detail.getWindowToken()); layout.removeView(submit); layout.addView(loading, submitParams); new FeedbackSender(sender.getText().toString(), detail.getText().toString()).execute(); } }); this.layout.addView(submit, submitParams); }