當前位置: 首頁>>代碼示例>>Java>>正文


Java Gravity.FILL_HORIZONTAL屬性代碼示例

本文整理匯總了Java中android.view.Gravity.FILL_HORIZONTAL屬性的典型用法代碼示例。如果您正苦於以下問題:Java Gravity.FILL_HORIZONTAL屬性的具體用法?Java Gravity.FILL_HORIZONTAL怎麽用?Java Gravity.FILL_HORIZONTAL使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在android.view.Gravity的用法示例。


在下文中一共展示了Gravity.FILL_HORIZONTAL屬性的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setGravity

/**
 * Set the location at which the notification should appear on the screen.
 *
 * @param gravity
 * @param xOffset
 * @param yOffset
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@Override
public IBuilder setGravity(int gravity, int xOffset, int yOffset) {

    // We can resolve the Gravity here by using the Locale for getting
    // the layout direction
    final int finalGravity;
    if (Build.VERSION.SDK_INT >= 14) {
        final Configuration config = mContext.getResources()
                .getConfiguration();
        finalGravity = Gravity.getAbsoluteGravity(gravity, config.getLayoutDirection());
    } else {
        finalGravity = gravity;
    }
    mBuilderParams.gravity = finalGravity;
    if ((finalGravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.FILL_HORIZONTAL) {
        mBuilderParams.horizontalWeight = 1.0f;
    }
    if ((finalGravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.FILL_VERTICAL) {
        mBuilderParams.verticalWeight = 1.0f;
    }
    mBuilderParams.y = yOffset;
    mBuilderParams.x = xOffset;
    return this;
}
 
開發者ID:gslovemy,項目名稱:ToastCompat,代碼行數:32,代碼來源:CustomToast.java

示例2: applyGravity

/**
 * apply the gravity for window params.
 *
 * @param expectGravity the expect gravity
 * @param applyWlp      the window layout params.
 */
private static void applyGravity(Context context,int expectGravity, WindowManager.LayoutParams applyWlp) {
    if (Build.VERSION.SDK_INT >= 17) {
        final Configuration configuration = context.getResources().getConfiguration();
        final int gravity = Gravity.getAbsoluteGravity(expectGravity, configuration.getLayoutDirection());
        applyWlp.gravity = gravity;
        if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.FILL_HORIZONTAL) {
            applyWlp.horizontalWeight = 1.0f;
        }
        if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.FILL_VERTICAL) {
            applyWlp.verticalWeight = 1.0f;
        }
    } else {
        applyWlp.gravity = expectGravity;
    }
}
 
開發者ID:LightSun,項目名稱:android-util2,代碼行數:21,代碼來源:BaseWindow.java

示例3: hitTest

private int hitTest(float x) {
    if (mPageCount == 0) {
        return -1;
    }

    float totalWidth = mPageCount * (mTabWidth + mTabSpacing) - mTabSpacing;
    float totalLeft;
    boolean fillHorizontal = false;

    switch (mGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.CENTER_HORIZONTAL:
            totalLeft = (getWidth() - totalWidth) / 2;
            break;
        case Gravity.RIGHT:
            totalLeft = getWidth() - getPaddingRight() - totalWidth;
            break;
        case Gravity.FILL_HORIZONTAL:
            totalLeft = getPaddingLeft();
            fillHorizontal = true;
            break;
        default:
            totalLeft = getPaddingLeft();
    }

    float tabWidth = mTabWidth;
    if (fillHorizontal) {
        tabWidth = (getWidth() - getPaddingRight() - getPaddingLeft()
                - (mPageCount - 1) * mTabSpacing) / mPageCount;
    }

    float totalRight = totalLeft + (mPageCount * (tabWidth + mTabSpacing));
    if (x >= totalLeft && x <= totalRight && totalRight > totalLeft) {
        return (int) (((x - totalLeft) / (totalRight - totalLeft)) * mPageCount);
    } else {
        return -1;
    }
}
 
開發者ID:andy1729,項目名稱:QuizApp,代碼行數:37,代碼來源:StepPagerStrip.java

示例4: addButtonForNetwork

private void addButtonForNetwork(AccessPointInfo info) {

        TableLayout s = (TableLayout) findViewById(R.id.table_networks);
        TableLayout.LayoutParams tableParams = new TableLayout.LayoutParams(
                        LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        TableRow row = new TableRow(this);
        TableRow.LayoutParams rowParams = new TableRow.LayoutParams(LayoutParams.MATCH_PARENT,
                        LayoutParams.WRAP_CONTENT);
        rowParams.gravity = Gravity.FILL_HORIZONTAL;
        row.setPadding(10, 10, 10, 10);
        row.setLayoutParams(rowParams);
        row.setGravity(Gravity.FILL_HORIZONTAL);
        row.setLayoutParams(rowParams);

        NetworkButton button = new NetworkButton(this, info.getBssid());

        TableRow.LayoutParams params = new TableRow.LayoutParams(LayoutParams.MATCH_PARENT,
                        LayoutParams.WRAP_CONTENT);
        button.setLayoutParams(params);
        button.setBackground(getResources().getDrawable(R.drawable.repwifi_button));
        button.setTextColor(Commons.colorThemeLight);
        button.setTextSize(20);
        button.setPadding(25, 10, 25, 10);
        button.setGravity(Gravity.CENTER_HORIZONTAL);
        button.setText(info.getSsid(20));
        button.setOnClickListener(this);

        row.addView(button, params);
        row.setGravity(Gravity.CENTER_HORIZONTAL);
        s.addView(row, tableParams);
        s.setGravity(Gravity.FILL_HORIZONTAL);

    }
 
開發者ID:vaginessa,項目名稱:RepWifiApp,代碼行數:33,代碼來源:SelectNetworkActivity.java

示例5: onDraw

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (mPageCount == 0) {
        return;
    }

    float totalWidth = mPageCount * (mTabWidth + mTabSpacing) - mTabSpacing;
    float totalLeft;
    boolean fillHorizontal = false;

    switch (mGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.CENTER_HORIZONTAL:
            totalLeft = (getWidth() - totalWidth) / 2;
            break;
        case Gravity.RIGHT:
            totalLeft = getWidth() - getPaddingRight() - totalWidth;
            break;
        case Gravity.FILL_HORIZONTAL:
            totalLeft = getPaddingLeft();
            fillHorizontal = true;
            break;
        default:
            totalLeft = getPaddingLeft();
    }

    switch (mGravity & Gravity.VERTICAL_GRAVITY_MASK) {
        case Gravity.CENTER_VERTICAL:
            mTempRectF.top = (int) (getHeight() - mTabHeight) / 2;
            break;
        case Gravity.BOTTOM:
            mTempRectF.top = getHeight() - getPaddingBottom() - mTabHeight;
            break;
        default:
            mTempRectF.top = getPaddingTop();
    }

    mTempRectF.bottom = mTempRectF.top + mTabHeight;

    float tabWidth = mTabWidth;
    if (fillHorizontal) {
        tabWidth = (getWidth() - getPaddingRight() - getPaddingLeft()
                - (mPageCount - 1) * mTabSpacing) / mPageCount;
    }

    for (int i = 0; i < mPageCount; i++) {
        mTempRectF.left = totalLeft + (i * (tabWidth + mTabSpacing));
        mTempRectF.right = mTempRectF.left + tabWidth;
        canvas.drawRect(mTempRectF, i < mCurrentPage
                ? mPrevTabPaint
                : (i > mCurrentPage
                ? mNextTabPaint
                : (i == mPageCount - 1
                ? mSelectedLastTabPaint
                : mSelectedTabPaint)));
    }
}
 
開發者ID:andy1729,項目名稱:QuizApp,代碼行數:58,代碼來源:StepPagerStrip.java


注:本文中的android.view.Gravity.FILL_HORIZONTAL屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。