android.widget.RelativeLayout#setFocusable ( )源码实例Demo

下面列出了android.widget.RelativeLayout#setFocusable ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Telegram-FOSS   文件: FloatingToolbar.java
private ViewGroup createContentContainer(Context context) {
    RelativeLayout contentContainer = new RelativeLayout(context);
    ViewGroup.MarginLayoutParams layoutParams = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutParams.bottomMargin = layoutParams.leftMargin = layoutParams.topMargin = layoutParams.rightMargin = AndroidUtilities.dp(20);
    contentContainer.setLayoutParams(layoutParams);
    contentContainer.setElevation(AndroidUtilities.dp(2));
    contentContainer.setFocusable(true);
    contentContainer.setFocusableInTouchMode(true);
    GradientDrawable shape = new GradientDrawable();
    shape.setShape(GradientDrawable.RECTANGLE);
    int r = AndroidUtilities.dp(6);
    shape.setCornerRadii(new float[] { r, r, r, r, r, r, r, r });
    if (currentStyle == STYLE_DIALOG) {
        shape.setColor(Theme.getColor(Theme.key_dialogBackground));
    } else if (currentStyle == STYLE_BLACK) {
        shape.setColor(0xf9222222);
    } else if (currentStyle == STYLE_THEME) {
        shape.setColor(Theme.getColor(Theme.key_windowBackgroundWhite));
    }
    contentContainer.setBackgroundDrawable(shape);
    contentContainer.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    contentContainer.setClipToOutline(true);
    return contentContainer;
}
 
源代码2 项目: Telegram   文件: FloatingToolbar.java
private ViewGroup createContentContainer(Context context) {
    RelativeLayout contentContainer = new RelativeLayout(context);
    ViewGroup.MarginLayoutParams layoutParams = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutParams.bottomMargin = layoutParams.leftMargin = layoutParams.topMargin = layoutParams.rightMargin = AndroidUtilities.dp(20);
    contentContainer.setLayoutParams(layoutParams);
    contentContainer.setElevation(AndroidUtilities.dp(2));
    contentContainer.setFocusable(true);
    contentContainer.setFocusableInTouchMode(true);
    GradientDrawable shape = new GradientDrawable();
    shape.setShape(GradientDrawable.RECTANGLE);
    int r = AndroidUtilities.dp(6);
    shape.setCornerRadii(new float[] { r, r, r, r, r, r, r, r });
    if (currentStyle == STYLE_DIALOG) {
        shape.setColor(Theme.getColor(Theme.key_dialogBackground));
    } else if (currentStyle == STYLE_BLACK) {
        shape.setColor(0xf9222222);
    } else if (currentStyle == STYLE_THEME) {
        shape.setColor(Theme.getColor(Theme.key_windowBackgroundWhite));
    }
    contentContainer.setBackgroundDrawable(shape);
    contentContainer.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    contentContainer.setClipToOutline(true);
    return contentContainer;
}
 
源代码3 项目: TelePlus-Android   文件: TabsPagerTitleStrip.java
public void addTabWithCounter(final int position, View view)
{
    RelativeLayout tab = new RelativeLayout(getContext());
    tab.setFocusable(true);

    tabsContainer.addView(tab, FeaturedSettings.tabSettings.tabsShouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams);
    view.setBackgroundResource(btnBgRes);
    view.setOnClickListener(v ->
    {
        if (position == pager.getCurrentItem())
        {
            if (delegate != null)
                delegate.onTabClick();
        }
        else
        {
            if (pager != null)
                pager.setCurrentItem(position);
        }
    });

    tab.addView(view, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    tab.setSelected(position == currentPosition);

    TextView textView = new TextView(getContext());
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, FeaturedSettings.tabSettings.chatsTabCounterSize);
    textView.setTextColor(Theme.getColor(Theme.key_dialogBadgeText));
    textView.setGravity(Gravity.CENTER);

    GradientDrawable shape = new GradientDrawable();
    shape.setShape(GradientDrawable.RECTANGLE);
    shape.setCornerRadius(AndroidUtilities.dp(32));
    //noinspection deprecation
    textView.setBackgroundDrawable(shape);
    textView.setMinWidth(AndroidUtilities.dp(18));

    textView.setPadding(AndroidUtilities.dp(FeaturedSettings.tabSettings.chatsTabCounterSize > 10 ? FeaturedSettings.tabSettings.chatsTabCounterSize - 7 : 4), 0,
            AndroidUtilities.dp(FeaturedSettings.tabSettings.chatsTabCounterSize > 10 ? FeaturedSettings.tabSettings.chatsTabCounterSize - 7 : 4), 0);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    params.setMargins(AndroidUtilities.dp(3), AndroidUtilities.dp(5), AndroidUtilities.dp(3), AndroidUtilities.dp(5));
    params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    tab.addView(textView, params);
}
 
源代码4 项目: TelePlus-Android   文件: TabsPagerTitleStrip.java
public void addTabWithCounter(final int position, View view)
{
    RelativeLayout tab = new RelativeLayout(getContext());
    tab.setFocusable(true);

    tabsContainer.addView(tab, FeaturedSettings.tabSettings.tabsShouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams);
    view.setBackgroundResource(btnBgRes);
    view.setOnClickListener(v ->
    {
        if (position == pager.getCurrentItem())
        {
            if (delegate != null)
                delegate.onTabClick();
        }
        else
        {
            if (pager != null)
                pager.setCurrentItem(position);
        }
    });

    tab.addView(view, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    tab.setSelected(position == currentPosition);

    TextView textView = new TextView(getContext());
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, FeaturedSettings.tabSettings.chatsTabCounterSize);
    textView.setTextColor(Theme.getColor(Theme.key_dialogBadgeText));
    textView.setGravity(Gravity.CENTER);

    GradientDrawable shape = new GradientDrawable();
    shape.setShape(GradientDrawable.RECTANGLE);
    shape.setCornerRadius(AndroidUtilities.dp(32));
    //noinspection deprecation
    textView.setBackgroundDrawable(shape);
    textView.setMinWidth(AndroidUtilities.dp(18));

    textView.setPadding(AndroidUtilities.dp(FeaturedSettings.tabSettings.chatsTabCounterSize > 10 ? FeaturedSettings.tabSettings.chatsTabCounterSize - 7 : 4), 0,
            AndroidUtilities.dp(FeaturedSettings.tabSettings.chatsTabCounterSize > 10 ? FeaturedSettings.tabSettings.chatsTabCounterSize - 7 : 4), 0);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    params.setMargins(AndroidUtilities.dp(3), AndroidUtilities.dp(5), AndroidUtilities.dp(3), AndroidUtilities.dp(5));
    params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    tab.addView(textView, params);
}
 
源代码5 项目: starcor.xul   文件: XulDemoBaseActivity.java
private void initLayout() {
	mLayout = new RelativeLayout(this) {
		Rect drawingRc = new Rect();

		@Override
		protected void dispatchDraw(Canvas canvas) {
			getDrawingRect(drawingRc);
			if ((mXulPageRender != null) && mXulPageRender.beginDraw(canvas, drawingRc)) {
				super.dispatchDraw(canvas);
				mXulPageRender.endDraw();
			} else {
				super.dispatchDraw(canvas);
			}

			synchronized (mRedrawWaitableObject) {
				mRedrawWaitableObject.notifyAll();
			}
		}

		@Override
		protected void onFocusChanged(boolean gainFocus, int direction,
		                              Rect previouslyFocusedRect) {
			super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
			if (!gainFocus) {
				LogUtil.d(TAG, "focus lost!!!!");
				post(new Runnable() {
					@Override
					public void run() {
						LogUtil.d(TAG, "update focus!!!!");
						View view = findFocus();
						IXulExternalView xulView = null;
						if (view != null) {
							if (view instanceof IXulExternalView) {
								xulView = (IXulExternalView) view;
							} else {
								ViewParent vp = view.getParent();
								while (vp != null && !(vp instanceof IXulExternalView)) {
									vp = vp.getParent();
								}
								if (vp != null) {
									xulView = (IXulExternalView) vp;
								}
							}
						}
						if (xulView != null) {
							XulView customItemByExtView =
								mXulPageRender.findCustomItemByExtView(xulView);
							mXulPageRender.getLayout().requestFocus(customItemByExtView);
						}
					}
				});
			}
		}
	};
	mLayout.setFocusable(true);
	mLayout.setFocusableInTouchMode(true);
	mLayout.setLayoutParams(new RelativeLayout.LayoutParams(
		ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
}
 
源代码6 项目: appcan-android   文件: EBounceViewHeader.java
public EBounceViewHeader(Context context, int type) {
    super(context);
    setWillNotDraw(true);
    setBackgroundColor(0);
    setFocusable(false);
    ESystemInfo intence = ESystemInfo.getIntence();
    int height = intence.mDefaultBounceHeight;
    RelativeLayout wapper = new RelativeLayout(context);
    wapper.setWillNotDraw(true);
    wapper.setBackgroundColor(0);
    wapper.setFocusable(false);
    RelativeLayout.LayoutParams wParm = new LayoutParams(-1, height);
    if (type == EViewEntry.F_BOUNCE_TYPE_TOP) {
        wParm.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    } else {
        wParm.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
    }
    wapper.setLayoutParams(wParm);
    addView(wapper);

    wap = new RelativeLayout(context);
    wap.setId(F_WAP_ID);
    RelativeLayout.LayoutParams wm = new LayoutParams(-2, height);
    wm.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
    wm.leftMargin = 30;
    wap.setLayoutParams(wm);

    mContent = new TextView(context);
    mContent.setId(F_CONTENT_ID);
    RelativeLayout.LayoutParams parmMsg = new LayoutParams(-2, -2);
    parmMsg.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
    mContent.setLayoutParams(parmMsg);
    mContent.setTextColor(textColor);
    mContent.setText(pullToReloadText);
    mContent.setTextSize(TypedValue.COMPLEX_UNIT_DIP, (float) (intence.mDefaultNatvieFontSize));
    mContent.setVisibility(GONE);
    wap.addView(mContent);

    mLevelContent = new TextView(context);
    RelativeLayout.LayoutParams parml = new LayoutParams(-2, -2);
    parml.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
    parml.addRule(RelativeLayout.BELOW, F_CONTENT_ID);
    mLevelContent.setLayoutParams(parml);
    mLevelContent.setTextColor(textColor);
    mLevelContent.setTextSize(TypedValue.COMPLEX_UNIT_DIP, (float) (intence.mDefaultNatvieFontSize * 0.6));
    mLevelContent.setVisibility(GONE);
    wap.addView(mLevelContent);

    wapper.addView(wap);

    mProgress = new ProgressBar(context);
    mProgress.setIndeterminate(true);
    int use = height - 12;
    RelativeLayout.LayoutParams parmPro = new LayoutParams(use, use);
    parmPro.addRule(RelativeLayout.LEFT_OF, F_WAP_ID);
    parmPro.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
    mProgress.setLayoutParams(parmPro);
    mProgress.setVisibility(GONE);
    wapper.addView(mProgress);

    mYAxisProgress = new YAxisImageView(context);
    int useY = height - 12;
    RelativeLayout.LayoutParams parmProY = new LayoutParams(useY, useY);
    parmProY.addRule(RelativeLayout.LEFT_OF, F_WAP_ID);
    parmProY.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
    mYAxisProgress.setLayoutParams(parmProY);
    mYAxisProgress.setVisibility(GONE);
    wapper.addView(mYAxisProgress);

    mArrowImage = new ImageView(context);
    int useA = height - 12;
    RelativeLayout.LayoutParams parmImage = new LayoutParams(useA, useA);
    parmImage.addRule(RelativeLayout.LEFT_OF, F_WAP_ID);
    parmImage.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
    mArrowImage.setLayoutParams(parmImage);
    Drawable icon = context.getResources().getDrawable(EResources.platform_myspace_pulltorefresh_arrow);
    mArrowImage.setImageDrawable(icon);
    mArrowImage.setVisibility(GONE);
    wapper.addView(mArrowImage);

    mAnimationUp = new RotateAnimation(-180, 0,
            RotateAnimation.RELATIVE_TO_SELF, 0.5f,
            RotateAnimation.RELATIVE_TO_SELF, 0.5f);
    mAnimationUp.setInterpolator(new AccelerateInterpolator());
    mAnimationUp.setDuration(250);
    mAnimationUp.setFillAfter(true);

    mAnimationDown = new RotateAnimation(0, -180,
            RotateAnimation.RELATIVE_TO_SELF, 0.5f,
            RotateAnimation.RELATIVE_TO_SELF, 0.5f);
    mAnimationDown.setInterpolator(new AccelerateInterpolator());
    mAnimationDown.setDuration(250);
    mAnimationDown.setFillAfter(true);
}