List of usage examples for android.widget TextView setLayoutParams
public void setLayoutParams(ViewGroup.LayoutParams params)
From source file:de.fahrgemeinschaft.util.ReoccuringWeekDaysView.java
private TextView makeRecurringDayButton(Context ctx) { TextView day = new UnScrollingTextView(ctx); if (clickable) day.setOnClickListener(toggleSelectedState); LayoutParams lp = new LayoutParams(0, LayoutParams.MATCH_PARENT); lp.weight = 1;// ww w. jav a 2 s . c om day.setLayoutParams(lp); day.setTextAppearance(getContext(), R.style.dark_Bold); day.setBackgroundResource(R.drawable.btn_night); day.setGravity(Gravity.CENTER); day.setFocusable(true); return day; }
From source file:MainActivity.java
public void goAnimate(View view) { ViewGroup root = (ViewGroup) findViewById(R.id.layout); Scene scene = new Scene(root); Transition transition = new ChangeBounds(); TransitionManager.beginDelayedTransition(root, transition); TextView textViewTop = (TextView) findViewById(R.id.textViewTop); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) textViewTop.getLayoutParams(); params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 1); params.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0); textViewTop.setLayoutParams(params); TextView textViewBottom = (TextView) findViewById(R.id.textViewBottom); params = (RelativeLayout.LayoutParams) textViewBottom.getLayoutParams(); params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 0); params.addRule(RelativeLayout.ALIGN_PARENT_TOP, 1); textViewBottom.setLayoutParams(params); TransitionManager.go(scene);//from w ww. ja va 2s .c o m }
From source file:eu.geopaparazzi.library.forms.views.GPictureView.java
/** * @param noteId the id of the note this image belows to. * @param fragmentDetail the fragment detail to use. * @param attrs attributes. * @param requestCode the code for starting the activity with result. * @param parentView parent//from w w w . j a va 2 s . c o m * @param key key * @param value in case of pictures, the value are the ids of the image, semicolonseparated. * @param constraintDescription constraints */ public GPictureView(final long noteId, final FragmentDetail fragmentDetail, AttributeSet attrs, final int requestCode, LinearLayout parentView, String key, String value, String constraintDescription) { super(fragmentDetail.getActivity(), attrs); _value = value; final FragmentActivity activity = fragmentDetail.getActivity(); LinearLayout textLayout = new LinearLayout(activity); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); layoutParams.setMargins(10, 10, 10, 10); textLayout.setLayoutParams(layoutParams); textLayout.setOrientation(LinearLayout.VERTICAL); parentView.addView(textLayout); TextView textView = new TextView(activity); textView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); textView.setPadding(2, 2, 2, 2); textView.setText(key.replace(UNDERSCORE, " ").replace(COLON, " ") + " " + constraintDescription); textView.setTextColor(activity.getResources().getColor(R.color.formcolor)); textLayout.addView(textView); final Button button = new Button(activity); button.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); button.setPadding(15, 5, 15, 5); button.setText(R.string.take_picture); textLayout.addView(button); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); double[] gpsLocation = PositionUtilities.getGpsLocationFromPreferences(preferences); String imageName = ImageUtilities.getCameraImageName(null); Intent cameraIntent = new Intent(activity, CameraActivity.class); cameraIntent.putExtra(LibraryConstants.PREFS_KEY_CAMERA_IMAGENAME, imageName); cameraIntent.putExtra(LibraryConstants.DATABASE_ID, noteId); if (gpsLocation != null) { cameraIntent.putExtra(LibraryConstants.LATITUDE, gpsLocation[1]); cameraIntent.putExtra(LibraryConstants.LONGITUDE, gpsLocation[0]); cameraIntent.putExtra(LibraryConstants.ELEVATION, gpsLocation[2]); } fragmentDetail.startActivityForResult(cameraIntent, requestCode); } }); ScrollView scrollView = new ScrollView(activity); ScrollView.LayoutParams scrollLayoutParams = new ScrollView.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); scrollView.setLayoutParams(scrollLayoutParams); parentView.addView(scrollView); imageLayout = new LinearLayout(activity); LinearLayout.LayoutParams imageLayoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); imageLayout.setLayoutParams(imageLayoutParams); imageLayout.setOrientation(LinearLayout.HORIZONTAL); scrollView.addView(imageLayout); try { refresh(activity); } catch (Exception e) { GPLog.error(this, null, e); } }
From source file:ch.pantas.billsplitter.ui.FixedTabsView.java
private void addTab(final int position, String title) { TextView tab = new TextView(getContext()); tab.setText(title);//w w w . j av a 2s . co m tab.setGravity(Gravity.CENTER); tab.setSingleLine(); tab.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 1f)); tab.setFocusable(true); tab.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { viewPager.setCurrentItem(position); } }); tabsContainer.addView(tab, position); }
From source file:com.t28.draggableview.demo.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)}.//from w ww . j a v a 2s . co m */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); textView.setLayoutParams( new SlidingTabStrip.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f)); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); textView.setTypeface(Typeface.DEFAULT_BOLD); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // If we're running on Honeycomb or newer, then we can use the Theme's // selectableItemBackground to ensure that the View has a pressed state TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style textView.setAllCaps(true); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); return textView; }
From source file:com.example.chicharo.clean_ambar.util.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)}./*from ww w . j ava2s. co m*/ */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); textView.setLayoutParams(new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1f)); // textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); textView.setTypeface(Typeface.DEFAULT_BOLD); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // If we're running on Honeycomb or newer, then we can use the Theme's // selectableItemBackground to ensure that the View has a pressed state TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, //Ripple effect outValue, true); textView.setBackgroundResource(outValue.resourceId); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style textView.setAllCaps(true); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); return textView; }
From source file:ca.farrelltonsolar.classic.DayLogCalendar.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { theView = inflater.inflate(R.layout.day_log_calendar, container, false); Bundle args = getArguments();/*from www. j a v a2 s.c om*/ int monthOffset = args != null ? args.getInt(ARG_MONTH) : 0; month = DateTime.now().minusMonths(monthOffset).withTimeAtStartOfDay().withDayOfMonth(1); adapter = new CalendarAdapter(this.getActivity(), month); GridView gridview = (GridView) theView.findViewById(R.id.gridview); gridview.setAdapter(adapter); gridview.setVelocityScale(5); TextView title = (TextView) theView.findViewById(R.id.title); title.setText(month.toString("MMMM yyyy")); View linearLayout = theView.findViewById(R.id.headerlayout); DateTime days = month; for (int i = 0; i < 7; i++) { int d = ((i + 6) % 7) + 1; days = days.withDayOfWeek(d); TextView aDay = new TextView(theView.getContext()); aDay.setText(DateTimeFormat.forPattern("E").print(days)); aDay.setGravity(Gravity.CENTER); aDay.setTextColor(Color.BLACK); aDay.setLayoutParams(new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1)); ((LinearLayout) linearLayout).addView(aDay); } return theView; }
From source file:com.rolmex.android.nemalltone.fragment.ViewPageFragment.java
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { context = getActivity();//from www . j av a2 s . co m View mView = inflater.inflate(R.layout.view_main, null); // int[] attrs = { android.R.attr.windowBackground }; TypedValue outValue = new TypedValue(); context.getTheme().resolveAttribute(android.R.attr.windowBackground, outValue, true); TypedArray style = context.getTheme().obtainStyledAttributes(outValue.resourceId, attrs); windowBackground = style.getDrawable(0); style.recycle(); // head_layout = (RelativeLayout)mView.findViewById(R.id.head_layout); // head_layout.setBackground(windowBackground); // ?? table_layout = (LinearLayout) mView.findViewById(R.id.table_layout); // table_layout.setBackground(windowBackground); // table_layout.setBackgroundResource(context.getResources().getColor(R.color.white)); DisplayMetrics dm = new DisplayMetrics(); ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(dm); // ??veiwPager?2 width = dm.widthPixels / 2 - 1; hsv = (HorizontalScrollView) mView.findViewById(R.id.main_ho_sv); hfl = (FrameLayout) mView.findViewById(R.id.main_fl); TextView placeView = new TextView(context); placeView.setLayoutParams(new FrameLayout.LayoutParams(width * 2, 10)); placeView.setBackgroundResource(R.color.half_white); hfl.addView(placeView); slidView = new TextView(context); slidView.setLayoutParams(new FrameLayout.LayoutParams(width, 10)); slidView.setBackgroundResource(R.color.holo_blue); hfl.addView(slidView); home_view = (TextView) mView.findViewById(R.id.home_mian_view); always_view = (TextView) mView.findViewById(R.id.home_always_view); showLeft = (Button) mView.findViewById(R.id.showLeft); showRight = (Button) mView.findViewById(R.id.showRight); mPager = (JazzyViewPager) mView.findViewById(R.id.pager); /** * ? */ mPager.setTransitionEffect(TransitionEffect.FlipHorizontal); PageFragment1 page1 = new PageFragment1(); PageFragment2 page2 = new PageFragment2(); pagerItemList.add(page1); pagerItemList.add(page2); mAdapter = new MyAdapter(getFragmentManager()); mPager.setAdapter(mAdapter); mPager.setPageMargin(30); mPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageSelected(int position) { updateTableBg(position); slidView.setTranslationX(width * position); if (myPageChangeListener != null) myPageChangeListener.onPageSelected(position); } @Override public void onPageScrolled(int arg0, float arg1, int arg2) { if (arg1 > 0.0) slidView.setTranslationX(width * arg1); } @Override public void onPageScrollStateChanged(int position) { } }); return mView; }
From source file:eu.hydrologis.geopaparazzi.maptools.FeaturePageAdapter.java
@Override public Object instantiateItem(ViewGroup container, int position) { final Feature feature = featuresList.get(position); int bgColor = context.getResources().getColor(R.color.formbgcolor); int textColor = context.getResources().getColor(R.color.formcolor); ScrollView scrollView = new ScrollView(context); ScrollView.LayoutParams scrollLayoutParams = new ScrollView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);//from ww w .j a v a 2s.c om scrollLayoutParams.setMargins(10, 10, 10, 10); scrollView.setLayoutParams(scrollLayoutParams); scrollView.setBackgroundColor(bgColor); LinearLayout linearLayoutView = new LinearLayout(context); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); int margin = 10; layoutParams.setMargins(margin, margin, margin, margin); linearLayoutView.setLayoutParams(layoutParams); linearLayoutView.setOrientation(LinearLayout.VERTICAL); int padding = 10; linearLayoutView.setPadding(padding, padding, padding, padding); scrollView.addView(linearLayoutView); List<String> attributeNames = feature.getAttributeNames(); List<String> attributeValues = feature.getAttributeValuesStrings(); List<String> attributeTypes = feature.getAttributeTypes(); for (int i = 0; i < attributeNames.size(); i++) { final String name = attributeNames.get(i); String value = attributeValues.get(i); String typeString = attributeTypes.get(i); DataType type = DataType.getType4Name(typeString); TextView textView = new TextView(context); textView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); textView.setPadding(padding, padding, padding, padding); textView.setText(name); textView.setTextColor(textColor); // textView.setTextAppearance(context, android.R.style.TextAppearance_Medium); linearLayoutView.addView(textView); final EditText editView = new EditText(context); LinearLayout.LayoutParams editViewParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); editViewParams.setMargins(margin, 0, margin, 0); editView.setLayoutParams(editViewParams); editView.setPadding(padding * 2, padding, padding * 2, padding); editView.setText(value); // editView.setEnabled(!isReadOnly); editView.setFocusable(!isReadOnly); // editView.setTextAppearance(context, android.R.style.TextAppearance_Medium); if (isReadOnly) { editView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { String text = editView.getText().toString(); FeatureUtilities.viewIfApplicable(v.getContext(), text); return false; } }); } switch (type) { case DOUBLE: case FLOAT: editView.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); break; case PHONE: editView.setInputType(InputType.TYPE_CLASS_PHONE); break; case DATE: editView.setInputType(InputType.TYPE_CLASS_DATETIME); break; case INTEGER: editView.setInputType(InputType.TYPE_CLASS_NUMBER); break; default: break; } editView.addTextChangedListener(new TextWatcher() { public void onTextChanged(CharSequence s, int start, int before, int count) { // ignore } public void beforeTextChanged(CharSequence s, int start, int count, int after) { // ignore } public void afterTextChanged(Editable s) { String text = editView.getText().toString(); feature.setAttribute(name, text); } }); linearLayoutView.addView(editView); } /* * add also area and length */ if (feature.getOriginalArea() > -1) { TextView areaTextView = new TextView(context); areaTextView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); areaTextView.setPadding(padding, padding, padding, padding); areaTextView.setText("Area: " + areaLengthFormatter.format(feature.getOriginalArea())); areaTextView.setTextColor(textColor); TextView lengthTextView = new TextView(context); lengthTextView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); lengthTextView.setPadding(padding, padding, padding, padding); lengthTextView.setText("Length: " + areaLengthFormatter.format(feature.getOriginalLength())); lengthTextView.setTextColor(textColor); linearLayoutView.addView(areaTextView); linearLayoutView.addView(lengthTextView); } container.addView(scrollView); return scrollView; }
From source file:com.i2max.i2smartwork.common.work.WorkDetailViewFragment.java
public void setFilesLayout(String title, LinearLayout targetLayout, Object object) { final List<LinkedTreeMap<String, String>> filesList = (List<LinkedTreeMap<String, String>>) object; if (filesList == null || filesList.size() <= 0) { targetLayout.setVisibility(View.GONE); } else {//from ww w .j a v a 2 s . c o m Log.e(TAG, "fileList size =" + filesList.size()); targetLayout.setVisibility(View.VISIBLE); targetLayout.removeAllViews(); //addTitleView LinearLayout.LayoutParams tvParam = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); tvParam.setMargins(0, DisplayUtil.dip2px(getActivity(), 12), 0, DisplayUtil.dip2px(getActivity(), 10)); TextView tvTitle = new TextView(getActivity()); tvTitle.setLayoutParams(tvParam); if (Build.VERSION.SDK_INT < 23) { tvTitle.setTextAppearance(getActivity(), android.R.style.TextAppearance_Material_Medium); } else { tvTitle.setTextAppearance(android.R.style.TextAppearance_Material_Medium); } tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15); tvTitle.setTextColor(getResources().getColor(R.color.text_color_black)); tvTitle.setText(title); targetLayout.addView(tvTitle); //addFilesView for (int i = 0; i < filesList.size(); i++) { final LinkedTreeMap<String, String> fileMap = filesList.get(i); LayoutInflater inflater = (LayoutInflater) getActivity() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View fileView = inflater.inflate(R.layout.view_item_file, null); ImageView ivIcFileExt = (ImageView) fileView.findViewById(R.id.iv_ic_file_ext); TextView tvFileNm = (TextView) fileView.findViewById(R.id.tv_file_nm); //?? ? ivIcFileExt.setImageResource(R.drawable.ic_file_doc); String fileNm = FormatUtil.getStringValidate(fileMap.get("file_nm")); tvFileNm.setText(fileNm); FileUtil.setFileExtIcon(ivIcFileExt, fileNm); final String fileExt = FileUtil.getFileExtsion(fileNm); final String downloadURL = I2UrlHelper.File .getDownloadFile(FormatUtil.getStringValidate(fileMap.get("file_id"))); fileView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = null; if ("Y".equals(FormatUtil.getStringValidate(fileMap.get("conv_yn")))) { //i2viewer ? ( conv_yn='Y') intent = IntentUtil.getI2ViewerIntent( FormatUtil.getStringValidate(fileMap.get("file_id")), FormatUtil.getStringValidate(fileMap.get("file_nm"))); getActivity().startActivity(intent); } else if ("mp4".equalsIgnoreCase(fileExt) || "fla".equalsIgnoreCase(fileExt) || "wmv".equalsIgnoreCase(fileExt) || "avi".equalsIgnoreCase(fileExt)) { //video intent = IntentUtil.getVideoPlayIntent(downloadURL); } else { //? ?? intent = new Intent(Intent.ACTION_VIEW, Uri.parse(downloadURL)); Bundle bundle = new Bundle(); bundle.putString("Authorization", I2UrlHelper.getTokenAuthorization()); intent.putExtra(Browser.EXTRA_HEADERS, bundle); Log.d(TAG, "intent:" + intent.toString()); } getActivity().startActivity(intent); } }); targetLayout.addView(fileView); } } }