List of usage examples for android.content.res Resources getDimensionPixelSize
public int getDimensionPixelSize(@DimenRes int id) throws NotFoundException
From source file:com.nile.kmooc.view.custom.popup.menu.MenuPopupHelper.java
public MenuPopupHelper(Context context, MenuBuilder menu, View anchorView, boolean overflowOnly, int popupStyleAttr, int popupStyleRes) { mContext = context;//from w w w .j a v a 2 s . c o m mInflater = LayoutInflater.from(context); mMenu = menu; mAdapter = new MenuAdapter(); mOverflowOnly = overflowOnly; mPopupStyleAttr = popupStyleAttr; mPopupStyleRes = popupStyleRes; final Resources res = context.getResources(); mPopupMaxWidth = Math.max(res.getDisplayMetrics().widthPixels / 2, res.getDimensionPixelSize(android.support.v7.appcompat.R.dimen.abc_config_prefDialogWidth)); TypedArray a = context.obtainStyledAttributes(null, R.styleable.PopupMenu, mPopupStyleAttr, mPopupStyleRes); mPopupMinWidth = a.getDimensionPixelSize(R.styleable.PopupMenu_android_minWidth, 0); int popupPadding = a.getDimensionPixelSize(R.styleable.PopupMenu_android_padding, -1); if (popupPadding >= 0) { mPopupPaddingLeft = popupPadding; mPopupPaddingRight = popupPadding; mPopupPaddingStart = popupPadding; mPopupPaddingEnd = popupPadding; mPopupPaddingTop = popupPadding; mPopupPaddingBottom = popupPadding; } else { int paddingStart = Integer.MIN_VALUE; int paddingEnd = Integer.MIN_VALUE; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { paddingStart = a.getDimensionPixelSize(R.styleable.PopupMenu_android_paddingStart, Integer.MIN_VALUE); paddingEnd = a.getDimensionPixelSize(R.styleable.PopupMenu_android_paddingEnd, Integer.MIN_VALUE); } int paddingLeft = 0; int paddingRight = 0; if (paddingStart == Integer.MIN_VALUE && paddingEnd == Integer.MIN_VALUE) { paddingLeft = a.getDimensionPixelSize(R.styleable.PopupMenu_android_paddingLeft, 0); paddingRight = a.getDimensionPixelSize(R.styleable.PopupMenu_android_paddingRight, 0); } else { if (paddingStart == Integer.MIN_VALUE) { paddingStart = 0; } if (paddingEnd == Integer.MIN_VALUE) { paddingEnd = 0; } } mPopupPaddingLeft = paddingLeft; mPopupPaddingRight = paddingRight; mPopupPaddingStart = paddingStart; mPopupPaddingEnd = paddingEnd; mPopupPaddingTop = a.getDimensionPixelSize(R.styleable.PopupMenu_android_paddingTop, 0); mPopupPaddingBottom = a.getDimensionPixelSize(R.styleable.PopupMenu_android_paddingBottom, 0); } mPopupItemVerticalPadding = a.getDimensionPixelSize(R.styleable.PopupMenu_itemVerticalPadding, 0); mPopupIconPadding = a.getDimensionPixelSize(R.styleable.PopupMenu_iconPadding, 0); mPopupIconDefaultSize = a.getDimensionPixelSize(R.styleable.PopupMenu_iconDefaultSize, 0); a.recycle(); mAnchorView = anchorView; // Present the menu using our context, not the menu builder's context. menu.addMenuPresenter(this, context); }
From source file:com.syncedsynapse.kore2.ui.MovieDetailsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { movieId = getArguments().getInt(MOVIEID, -1); if ((container == null) || (movieId == -1)) { // We're not being shown or there's nothing to show return null; }// w ww. j ava2 s . c o m ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_movie_details, container, false); ButterKnife.inject(this, root); bus = EventBus.getDefault(); hostManager = HostManager.getInstance(getActivity()); hostInfo = hostManager.getHostInfo(); swipeRefreshLayout.setOnRefreshListener(this); //UIUtils.setSwipeRefreshLayoutColorScheme(swipeRefreshLayout); // Setup dim the fanart when scroll changes. Full dim on 4 * iconSize dp Resources resources = getActivity().getResources(); final int pixelsToTransparent = 4 * resources.getDimensionPixelSize(R.dimen.default_icon_size); mediaPanel.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() { @Override public void onScrollChanged() { float y = mediaPanel.getScrollY(); float newAlpha = Math.min(1, Math.max(0, 1 - (y / pixelsToTransparent))); mediaArt.setAlpha(newAlpha); } }); FloatingActionButton fab = (FloatingActionButton) fabButton; fab.attachToScrollView((ObservableScrollView) mediaPanel); // Pad main content view to overlap with bottom system bar // UIUtils.setPaddingForSystemBars(getActivity(), mediaPanel, false, false, true); // mediaPanel.setClipToPadding(false); return root; }
From source file:com.italankin.dictionary.ui.main.MainActivity.java
private void setupRecyclerView() { mRecyclerView.setHasFixedSize(true); mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); Resources res = getResources(); int left = res.getDimensionPixelSize(R.dimen.list_item_margin_left); int top = res.getDimensionPixelSize(R.dimen.list_item_margin_top); int right = res.getDimensionPixelSize(R.dimen.list_item_margin_right); int bottom = res.getDimensionPixelSize(R.dimen.list_item_margin_bottom); mRecyclerView.addItemDecoration(new SimpleItemDecoration(left, top, right, bottom)); // allow input layout to be scrolled along with recycler view mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override//from w w w. j av a2 s . c om public void onScrolled(RecyclerView recyclerView, int dx, int dy) { updateInputLayoutPosition(); } }); top = getResources().getDimensionPixelSize(R.dimen.list_top_offset); int inputHeight = getResources().getDimensionPixelSize(R.dimen.input_panel_height); mRecyclerView.setPadding(mRecyclerView.getPaddingLeft(), inputHeight + top, mRecyclerView.getPaddingRight(), mRecyclerView.getPaddingBottom()); // on click listener mRecyclerViewAdapter = new TranslationAdapter(this); mRecyclerViewAdapter.setListener(new TranslationAdapter.OnAdapterItemClickListener() { @Override public void onItemClick(int position) { TranslationEx item = _presenter.getLastResult().translations.get(position); startActivity(TranslationActivity.getStartIntent(getApplicationContext(), item)); } @Override public void onItemMenuClick(int position, int menuItemId) { ClipData clip = null; TranslationEx item = _presenter.getLastResult().translations.get(position); switch (menuItemId) { case R.id.action_lookup_word: lookupNext(item.text); break; case R.id.action_copy_mean: clip = ClipData.newPlainText("means", item.means); break; case R.id.action_copy_synonyms: clip = ClipData.newPlainText("synonyms", item.synonyms); break; case R.id.action_copy_translation: clip = ClipData.newPlainText("translation", item.text); break; } if (clip != null) { mClipboardManager.setPrimaryClip(clip); Toast.makeText(MainActivity.this, R.string.msg_copied, Toast.LENGTH_SHORT).show(); } } }); mRecyclerView.setAdapter(mRecyclerViewAdapter); }
From source file:com.tct.mail.browse.ConversationItemViewCoordinates.java
private ConversationItemViewCoordinates(final Context context, final Config config, final CoordinatesCache cache) { Utils.traceBeginSection("CIV coordinates constructor"); final Resources res = context.getResources(); mMinListWidthForWide = res.getDimensionPixelSize(R.dimen.list_min_width_is_wide); mMode = calculateMode(res, config);// w w w.jav a 2 s. c om final int layoutId = R.layout.conversation_item_view; ViewGroup view = (ViewGroup) cache.getView(layoutId); if (view == null) { view = (ViewGroup) LayoutInflater.from(context).inflate(layoutId, null); cache.put(layoutId, view); } // Show/hide optional views before measure/layout call final TextView folders = (TextView) view.findViewById(R.id.folders); folders.setVisibility(config.areFoldersVisible() ? View.VISIBLE : View.GONE); View contactImagesView = view.findViewById(R.id.contact_image); switch (config.getGadgetMode()) { case GADGET_CONTACT_PHOTO: contactImagesView.setVisibility(View.VISIBLE); break; case GADGET_CHECKBOX: contactImagesView.setVisibility(View.GONE); contactImagesView = null; break; default: contactImagesView.setVisibility(View.GONE); contactImagesView = null; break; } final View replyState = view.findViewById(R.id.reply_state); replyState.setVisibility(config.isReplyStateVisible() ? View.VISIBLE : View.GONE); final View personalIndicator = view.findViewById(R.id.personal_indicator); personalIndicator.setVisibility(config.isPersonalIndicatorVisible() ? View.VISIBLE : View.GONE); setFramePadding(context, view, config.useFullPadding()); // Layout the appropriate view. ViewCompat.setLayoutDirection(view, config.getLayoutDirection()); final int widthSpec = MeasureSpec.makeMeasureSpec(config.getWidth(), MeasureSpec.EXACTLY); final int heightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); view.measure(widthSpec, heightSpec); view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); // Once the view is measured, let's calculate the dynamic width variables. folderLayoutWidth = (int) (view.getWidth() * res.getInteger(R.integer.folder_max_width_proportion) / 100.0); folderCellWidth = (int) (view.getWidth() * res.getInteger(R.integer.folder_cell_max_width_proportion) / 100.0); // Utils.dumpViewTree((ViewGroup) view); // Records coordinates. // Contact images view if (contactImagesView != null) { contactImagesWidth = contactImagesView.getWidth(); contactImagesHeight = contactImagesView.getHeight(); contactImagesX = getX(contactImagesView); contactImagesY = getY(contactImagesView); } else { contactImagesX = contactImagesY = contactImagesWidth = contactImagesHeight = 0; } final boolean isRtl = ViewUtils.isViewRtl(view); final View star = view.findViewById(R.id.star); final int starPadding = res.getDimensionPixelSize(R.dimen.conv_list_star_padding_start); starX = getX(star) + (isRtl ? 0 : starPadding); starY = getY(star); starWidth = star.getWidth(); final TextView senders = (TextView) view.findViewById(R.id.senders); final int sendersTopAdjust = getLatinTopAdjustment(senders); sendersX = getX(senders); sendersY = getY(senders) + sendersTopAdjust; sendersWidth = senders.getWidth(); sendersHeight = senders.getHeight(); sendersLineCount = SINGLE_LINE; sendersFontSize = senders.getTextSize(); final TextView subject = (TextView) view.findViewById(R.id.subject); final int subjectTopAdjust = getLatinTopAdjustment(subject); subjectX = getX(subject); subjectY = getY(subject) + subjectTopAdjust; subjectWidth = subject.getWidth(); subjectHeight = subject.getHeight(); subjectFontSize = subject.getTextSize(); // TS: chao.zhang 2015-09-14 EMAIL FEATURE-585337 ADD_S final TextView status = (TextView) view.findViewById(R.id.status); final int statusTopAdjust = getLatinTopAdjustment(status); statusX = getX(status); statusY = getY(status) + statusTopAdjust; statusWidth = status.getWidth(); statusHeight = status.getHeight(); statusFontSize = status.getTextSize(); statusPaddingStart = ViewUtils.getPaddingStart(status); statusPanddingEnd = ViewUtils.getPaddingEnd(status); // TS: chao.zhang 2015-09-14 EMAIL FEATURE-585337 ADD_E final TextView snippet = (TextView) view.findViewById(R.id.snippet); final int snippetTopAdjust = getLatinTopAdjustment(snippet); snippetX = getX(snippet); snippetY = getY(snippet) + snippetTopAdjust; maxSnippetWidth = snippet.getWidth(); snippetHeight = snippet.getHeight(); snippetFontSize = snippet.getTextSize(); if (config.areFoldersVisible()) { // vertically align folders min left edge with subject foldersLeft = getX(folders); foldersRight = foldersLeft + folders.getWidth(); foldersY = getY(folders) + sendersTopAdjust; foldersHeight = folders.getHeight(); foldersTypeface = folders.getTypeface(); foldersTextBottomPadding = res.getDimensionPixelSize(R.dimen.folders_text_bottom_padding); foldersFontSize = folders.getTextSize(); } else { foldersLeft = 0; foldersRight = 0; foldersY = 0; foldersHeight = 0; foldersTypeface = null; foldersTextBottomPadding = 0; foldersFontSize = 0; } final View colorBlock = view.findViewById(R.id.color_block); if (config.isColorBlockVisible() && colorBlock != null) { colorBlockX = getX(colorBlock); colorBlockY = getY(colorBlock); colorBlockWidth = colorBlock.getWidth(); colorBlockHeight = colorBlock.getHeight(); } else { colorBlockX = colorBlockY = colorBlockWidth = colorBlockHeight = 0; } if (config.isReplyStateVisible()) { replyStateX = getX(replyState); replyStateY = getY(replyState); } else { replyStateX = replyStateY = 0; } if (config.isPersonalIndicatorVisible()) { personalIndicatorX = getX(personalIndicator); personalIndicatorY = getY(personalIndicator); } else { personalIndicatorX = personalIndicatorY = 0; } final View infoIcon = view.findViewById(R.id.info_icon); infoIconX = getX(infoIcon); infoIconXRight = infoIconX + infoIcon.getWidth(); infoIconY = getY(infoIcon); final TextView date = (TextView) view.findViewById(R.id.date); dateX = getX(date); dateXRight = dateX + date.getWidth(); dateY = getY(date); datePaddingStart = ViewUtils.getPaddingStart(date); dateFontSize = date.getTextSize(); dateYBaseline = dateY + getLatinTopAdjustment(date) + date.getBaseline(); final View paperclip = view.findViewById(R.id.paperclip); paperclipY = getY(paperclip); paperclipPaddingStart = ViewUtils.getPaddingStart(paperclip); height = view.getHeight() + sendersTopAdjust; Utils.traceEndSection(); }
From source file:com.wizardsofm.deskclock.stopwatch.StopwatchFragment.java
/** * Show or hide the list of laps./*from ww w .j a v a 2 s . c o m*/ */ private void showOrHideLaps(boolean clearLaps) { final ViewGroup sceneRoot = (ViewGroup) getView(); if (sceneRoot == null) { return; } TransitionManager.beginDelayedTransition(sceneRoot); if (clearLaps) { mLapsAdapter.clearLaps(); } final boolean lapsVisible = mLapsAdapter.getItemCount() > 0; mLapsList.setVisibility(lapsVisible ? VISIBLE : GONE); if (Utils.isPortrait(getActivity())) { // When the lap list is visible, it includes the bottom padding. When it is absent the // appropriate bottom padding must be applied to the container. final Resources res = getResources(); final int bottom = lapsVisible ? 0 : res.getDimensionPixelSize(com.wizardsofm.deskclock.R.dimen.fab_height); final int top = sceneRoot.getPaddingTop(); final int left = sceneRoot.getPaddingLeft(); final int right = sceneRoot.getPaddingRight(); sceneRoot.setPadding(left, top, right, bottom); } }
From source file:org.xbmc.kore.ui.MovieDetailsFragment.java
@TargetApi(21) @Override/*from w w w. j a v a2 s.c o m*/ protected View createView(LayoutInflater inflater, ViewGroup container) { Bundle bundle = getArguments(); movieId = bundle.getInt(BUNDLE_KEY_MOVIEID, -1); if (movieId == -1) { // There's nothing to show return null; } ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_movie_details, container, false); ButterKnife.inject(this, root); //UIUtils.setSwipeRefreshLayoutColorScheme(swipeRefreshLayout); // Setup dim the fanart when scroll changes. Full dim on 4 * iconSize dp Resources resources = getActivity().getResources(); final int pixelsToTransparent = 4 * resources.getDimensionPixelSize(R.dimen.default_icon_size); mediaPanel.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() { @Override public void onScrollChanged() { float y = mediaPanel.getScrollY(); float newAlpha = Math.min(1, Math.max(0, 1 - (y / pixelsToTransparent))); mediaArt.setAlpha(newAlpha); } }); FloatingActionButton fab = (FloatingActionButton) fabButton; fab.attachToScrollView((ObservableScrollView) mediaPanel); if (Utils.isLollipopOrLater()) { mediaPoster.setTransitionName(getArguments().getString(POSTER_TRANS_NAME)); } mediaTitle.setText(bundle.getString(BUNDLE_KEY_MOVIETITLE)); mediaUndertitle.setText(bundle.getString(BUNDLE_KEY_MOVIEPLOT)); mediaGenres.setText(bundle.getString(BUNDLE_KEY_MOVIEGENRES)); setMediaYear(bundle.getInt(BUNDLE_KEY_MOVIERUNTIME), bundle.getInt(BUNDLE_KEY_MOVIEYEAR)); setMediaRating(bundle.getDouble(BUNDLE_KEY_MOVIERATING)); // Pad main content view to overlap with bottom system bar // UIUtils.setPaddingForSystemBars(getActivity(), mediaPanel, false, false, true); // mediaPanel.setClipToPadding(false); return root; }
From source file:org.runbuddy.tomahawk.ui.fragments.ContentHeaderFragment.java
private void setupFancyDropDownAnimation(final View view) { //?view//from w w w .j ava 2 s .c om if (view != null) { final FancyDropDown fancyDropDown = (FancyDropDown) view.findViewById(R.id.fancydropdown); if (fancyDropDown != null) { final Runnable r = new Runnable() { @Override public void run() { // get resources first Resources resources = TomahawkApp.getContext().getResources(); int dropDownHeight = resources.getDimensionPixelSize(R.dimen.show_context_menu_icon_height); int actionBarHeight = resources .getDimensionPixelSize(R.dimen.abc_action_bar_default_height_material); int smallPadding = resources.getDimensionPixelSize(R.dimen.padding_small); int superLargePadding = resources.getDimensionPixelSize(R.dimen.padding_superlarge); // now calculate the animation goal and instantiate the animation int initialX = view.getWidth() / 2 - fancyDropDown.getWidth() / 2; int initialY = view.getHeight() / 2 - dropDownHeight / 2; PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat("x", initialX, superLargePadding); PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat("y", initialY, actionBarHeight + smallPadding); ValueAnimator animator = ObjectAnimator.ofPropertyValuesHolder(fancyDropDown, pvhX, pvhY) .setDuration(10000); animator.setInterpolator(new LinearInterpolator()); addAnimator(ANIM_FANCYDROPDOWN_ID, animator); refreshAnimations(); } }; r.run(); fancyDropDown.setOnSizeChangedListener(new OnSizeChangedListener() { @Override public void onSizeChanged(int w, int h, int oldw, int oldh) { r.run(); } }); } } }
From source file:org.edx.mobile.view.custom.popup.menu.MenuPopupHelper.java
public MenuPopupHelper(Context context, MenuBuilder menu, View anchorView, boolean overflowOnly, int popupStyleAttr, int popupStyleRes) { mContext = context;/*from w w w . ja va2 s .c o m*/ mInflater = LayoutInflater.from(context); mMenu = menu; mAdapter = new MenuAdapter(); mOverflowOnly = overflowOnly; mPopupStyleAttr = popupStyleAttr; mPopupStyleRes = popupStyleRes; final Resources res = context.getResources(); mPopupMaxWidth = Math.max(res.getDisplayMetrics().widthPixels / 2, res.getDimensionPixelSize(android.support.v7.appcompat.R.dimen.abc_config_prefDialogWidth)); TypedArray a = context.obtainStyledAttributes(null, R.styleable.PopupMenu, mPopupStyleAttr, mPopupStyleRes); mPopupMinWidth = a.getDimensionPixelSize(R.styleable.PopupMenu_android_minWidth, 0); int popupPadding = a.getDimensionPixelSize(R.styleable.PopupMenu_android_padding, -1); if (popupPadding >= 0) { mPopupPaddingLeft = popupPadding; mPopupPaddingRight = popupPadding; mPopupPaddingStart = popupPadding; mPopupPaddingEnd = popupPadding; mPopupPaddingTop = popupPadding; mPopupPaddingBottom = popupPadding; } else { int paddingStart = Integer.MIN_VALUE; int paddingEnd = Integer.MIN_VALUE; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { paddingStart = a.getDimensionPixelSize(R.styleable.PopupMenu_android_paddingStart, Integer.MIN_VALUE); paddingEnd = a.getDimensionPixelSize(R.styleable.PopupMenu_android_paddingEnd, Integer.MIN_VALUE); } int paddingLeft = 0; int paddingRight = 0; if (paddingStart == Integer.MIN_VALUE && paddingEnd == Integer.MIN_VALUE) { paddingLeft = a.getDimensionPixelSize(R.styleable.PopupMenu_android_paddingLeft, 0); paddingRight = a.getDimensionPixelSize(R.styleable.PopupMenu_android_paddingRight, 0); } else { if (paddingStart == Integer.MIN_VALUE) { paddingStart = 0; } if (paddingEnd == Integer.MIN_VALUE) { paddingEnd = 0; } } mPopupPaddingLeft = paddingLeft; mPopupPaddingRight = paddingRight; mPopupPaddingStart = paddingStart; mPopupPaddingEnd = paddingEnd; mPopupPaddingTop = a.getDimensionPixelSize(R.styleable.PopupMenu_android_paddingTop, 0); mPopupPaddingBottom = a.getDimensionPixelSize(R.styleable.PopupMenu_android_paddingBottom, 0); } mPopupItemVerticalPadding = a.getDimensionPixelSize(R.styleable.PopupMenu_itemVerticalPadding, 0); mPopupIconPadding = a.getDimensionPixelSize(R.styleable.PopupMenu_iconPadding, 0); mPopupIconDefaultSize = a.getDimensionPixelSize(R.styleable.PopupMenu_iconDefaultSize, 0); mPopupHeaderTextAppearance = a.getResourceId(R.styleable.PopupMenu_headerTextAppearance, -1); mPopupRowTextAppearance = a.getResourceId(R.styleable.PopupMenu_rowTextAppearance, -1); a.recycle(); mAnchorView = anchorView; // Present the menu using our context, not the menu builder's context. menu.addMenuPresenter(this, context); }
From source file:com.btmura.android.reddit.app.AbstractBrowserActivity.java
private void setupCommonViews() { if (!isSinglePane) { getSupportFragmentManager().addOnBackStackChangedListener(this); navContainer = findViewById(R.id.nav_container); leftContainer = findViewById(R.id.left_container); rightContainer = findViewById(R.id.right_container); Resources r = getResources(); leftWidth = r.getDimensionPixelSize(R.dimen.left_width); fullNavWidth = r.getDisplayMetrics().widthPixels; }/*from w ww . j av a 2s . co m*/ measureThingBodyWidth(); }
From source file:fr.magistry.taigime.CandidateView.java
/** * Construct a CandidateView for showing suggested words for completion. * @param context/* w ww . j a v a 2s. c om*/ */ public CandidateView(Context context) { super(context); mSelectionHighlight = context.getResources().getDrawable(android.R.drawable.list_selector_background); mSelectionHighlight.setState(new int[] { android.R.attr.state_enabled, android.R.attr.state_focused, android.R.attr.state_window_focused, android.R.attr.state_pressed }); Resources r = context.getResources(); setBackgroundColor(r.getColor(R.color.candidate_background)); mColorNormal = r.getColor(R.color.candidate_normal); mColorRecommended = r.getColor(R.color.candidate_recommended); mColorOther = r.getColor(R.color.candidate_other); mVerticalPadding = r.getDimensionPixelSize(R.dimen.candidate_vertical_padding); mPaint = new Paint(); mPaint.setColor(mColorNormal); mPaint.setAntiAlias(true); mPaint.setTextSize(r.getDimensionPixelSize(R.dimen.candidate_font_height)); mPaint.setStrokeWidth(0); mPaintTRS = new Paint(); mPaintTRS.set(mPaint); mPaintTRS.setTextSize(r.getDimensionPixelSize(R.dimen.candidate_font_trs_height)); mPaintBPM = new Paint(); mPaintBPM.set(mPaintTRS); mGestureDetector = new GestureDetectorCompat(context, new GestureDetector.SimpleOnGestureListener() { @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { mScrolled = true; int sx = getScrollX(); sx += distanceX; if (sx < 0) { sx = 0; } if (sx + getWidth() > mTotalWidth) { sx -= distanceX; } mTargetScrollX = sx; scrollTo(sx, getScrollY()); invalidate(); return true; } }); setHorizontalFadingEdgeEnabled(true); setWillNotDraw(false); setHorizontalScrollBarEnabled(false); setVerticalScrollBarEnabled(false); updateConfig(context); }