Java Code Examples for android.widget.LinearLayout.LayoutParams

The following are Jave code examples for showing how to use LayoutParams of the android.widget.LinearLayout class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: oma-riista-android   File: SrvaEditFragment.java   View Source Code Vote up 6 votes
private void createSpecimenDetailsButton() {
    int margin = UiUtils.dipToPixels(getActivity(), 10);

    Button button = new Button(getActivity());
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    params.setMargins(margin, margin, margin, margin);
    button.setLayoutParams(params);
    button.setBackgroundResource(R.drawable.button);
    button.setText(R.string.specimen_details);
    mViewContainer.addView(button);

    button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getActivity(), SrvaSpecimenActivity.class);
            intent.putExtra(SrvaSpecimenActivity.EXTRA_SRVA_EVENT, mSrvaEvent);
            intent.putExtra(SrvaSpecimenActivity.EXTRA_EDIT_MODE, isEditModeOn());
            startActivityForResult(intent, SPECIMEN_REQUEST_CODE);
        }
    });
}
 
Example 2
Project: Hitalk   File: CommentListView.java   View Source Code Vote up 6 votes
public void notifyDataSetChanged(){

        removeAllViews();
        if(mDatas == null || mDatas.size() == 0){
            return;
        }
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        for(int i=0; i<mDatas.size(); i++){
            final int index = i;
            View view = getView(index);
            if(view == null){
                throw new NullPointerException("listview item layout is null, please check getView()...");
            }

            addView(view, index, layoutParams);
        }

    }
 
Example 3
Project: LiuAGeAndroid   File: EditPagePort.java   View Source Code Vote up 5 votes
private void initBottom(LinearLayout llBottom, float ratio) {
	LinearLayout llAt = new LinearLayout(activity);
	llAt.setPadding(0, 0, 0, 5);
	llAt.setBackgroundColor(0xffffffff);
	int bottomHeight = (int) (DESIGN_BOTTOM_HEIGHT * ratio);
	LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, bottomHeight);
	llBottom.addView(llAt, lp);

	tvAt = new TextView(activity);
	tvAt.setTextColor(0xff3b3b3b);
	tvAt.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22);
	tvAt.setGravity(Gravity.BOTTOM);
	tvAt.setText("@");
	int padding = (int) (DESIGN_LEFT_PADDING * ratio);
	tvAt.setPadding(padding, 0, padding, 0);
	lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
	llAt.addView(tvAt, lp);
	tvAt.setOnClickListener(this);
	if (isShowAtUserLayout(platform.getName())) {
		tvAt.setVisibility(View.VISIBLE);
	} else {
		tvAt.setVisibility(View.INVISIBLE);
	}

	tvTextCouter = new TextView(activity);
	tvTextCouter.setTextColor(0xff3b3b3b);
	tvTextCouter.setTextSize(TypedValue.COMPLEX_UNIT_SP, 21);
	tvTextCouter.setGravity(Gravity.BOTTOM | Gravity.RIGHT);
	onTextChanged(etContent.getText(), 0, 0, 0);
	tvTextCouter.setPadding(padding, 0, padding, 0);
	lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
	lp.weight = 1;
	llAt.addView(tvTextCouter, lp);

	View v = new View(activity);
	v.setBackgroundColor(0xffcccccc);
	int px_1 = ratio > 1 ? ((int) ratio) : 1;
	lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, px_1);
	llBottom.addView(v, lp);
}
 
Example 4
Project: shareNote   File: TabIconView.java   View Source Code Vote up 5 votes
private void init() {
    this.setOverScrollMode(OVER_SCROLL_NEVER);
    this.setHorizontalScrollBarEnabled(false);

    mInflater = LayoutInflater.from(getContext());

    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    mLayout = new LinearLayout(getContext());
    mLayout.setPadding(1, 0, 1, 0);
    mLayout.setOrientation(LinearLayout.HORIZONTAL);
    addView(mLayout, params);
}
 
Example 5
Project: QMUI_Android   File: QMUIBottomSheet.java   View Source Code Vote up 5 votes
private void setItemWidth(View itemView, int itemWidth) {
    LinearLayout.LayoutParams itemLp;
    if (itemView.getLayoutParams() != null) {
        itemLp = (LinearLayout.LayoutParams) itemView.getLayoutParams();
        itemLp.width = itemWidth;
    } else {
        itemLp = new LinearLayout.LayoutParams(itemWidth, ViewGroup.LayoutParams.WRAP_CONTENT);
        itemView.setLayoutParams(itemLp);
    }
    itemLp.gravity = Gravity.TOP;
}
 
Example 6
Project: sctalk   File: EmoGridViewAdapter.java   View Source Code Vote up 5 votes
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    try {
        GridViewHolder gridViewHolder = null;
        if (null == convertView && null != context) {
            gridViewHolder = new GridViewHolder();
            convertView = gridViewHolder.layoutView;
            if (convertView != null) {
                convertView.setTag(gridViewHolder);
            }
        } else {
            gridViewHolder = (GridViewHolder) convertView.getTag();
        }
        if (null == gridViewHolder || null == convertView) {
            return null;
        }
        gridViewHolder.faceIv.setImageBitmap(getBitmap(position));

        if (position == emoResIds.length - 1) {
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            params.topMargin = CommonUtil.getElementSzie(context) / 3;
            gridViewHolder.faceIv.setLayoutParams(params);
        }
        return convertView;
    } catch (Exception e) {
        logger.e(e.getMessage());
        return null;
    }
}
 
Example 7
Project: GalleryCycleImageView   File: GalleryCycleImageView.java   View Source Code Vote up 5 votes
@Override
public Object instantiateItem(ViewGroup container, int position) {
    //如果要自定义ItemView在这里操作
    ImageView imageView = new ImageView(mContext);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    imageView.setLayoutParams(params);
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    View v = null;
    if (mGalleyCycleImageListener != null)
        v = mGalleyCycleImageListener.setItem(imageView, getPosition(position));
    container.addView(v);
    return v;
}
 
Example 8
Project: YiZhi   File: SnackbarUtils.java   View Source Code Vote up 5 votes
/**
 * 向Snackbar中添加view
 *
 * @param snackbar
 * @param layoutId
 * @param index    新加布局在Snackbar中的位置
 */
public static void addView(Snackbar snackbar, int layoutId, int index) {
    View snackbarview = snackbar.getView();
    Snackbar.SnackbarLayout snackbarLayout = (Snackbar.SnackbarLayout) snackbarview;

    View add_view = LayoutInflater.from(snackbarview.getContext()).inflate(layoutId, null);

    LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams
            .WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    p.gravity = Gravity.CENTER_VERTICAL;

    snackbarLayout.addView(add_view, index, p);
}
 
Example 9
Project: QMUI_Android   File: QMUITopBar.java   View Source Code Vote up 5 votes
/**
 * 生成 titleView 或 subTitleView 的 LayoutParams
 */
private LinearLayout.LayoutParams generateTitleViewAndSubTitleViewLp() {
    LinearLayout.LayoutParams titleLp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    // 垂直居中
    titleLp.gravity = mTitleGravity;
    return titleLp;
}
 
Example 10
Project: LQRWeChat   File: EditPageLand.java   View Source Code Vote up 5 votes
private void initBottom(LinearLayout llBottom, float ratio) {
	LinearLayout llAt = new LinearLayout(activity);
	llAt.setPadding(0, 0, 0, 5);
	llAt.setBackgroundColor(0xffffffff);
	int bottomHeight = (int) (DESIGN_BOTTOM_HEIGHT * ratio);
	LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, bottomHeight);
	llBottom.addView(llAt, lp);

	tvAt = new TextView(activity);
	tvAt.setTextColor(0xff3b3b3b);
	tvAt.setTextSize(TypedValue.COMPLEX_UNIT_SP, 21);
	tvAt.setGravity(Gravity.BOTTOM);
	tvAt.setText("@");
	int padding = (int) (DESIGN_LEFT_PADDING * ratio);
	tvAt.setPadding(padding, 0, padding, 0);
	lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
	llAt.addView(tvAt, lp);
	tvAt.setOnClickListener(this);
	if (isShowAtUserLayout(platform.getName())) {
		tvAt.setVisibility(View.VISIBLE);
	} else {
		tvAt.setVisibility(View.INVISIBLE);
	}

	tvTextCouter = new TextView(activity);
	tvTextCouter.setTextColor(0xff3b3b3b);
	tvTextCouter.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
	tvTextCouter.setGravity(Gravity.BOTTOM | Gravity.RIGHT);
	onTextChanged(etContent.getText(), 0, 0, 0);
	tvTextCouter.setPadding(padding, 0, padding, 0);
	lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
	lp.weight = 1;
	llAt.addView(tvTextCouter, lp);

	View v = new View(activity);
	v.setBackgroundColor(0xffcccccc);
	int px1 = ratio > 1 ? ((int) ratio) : 1;
	lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, px1);
	llBottom.addView(v, lp);
}
 
Example 11
Project: EasyReader   File: StatusBarUtils.java   View Source Code Vote up 5 votes
private static StatusBarView createStatusBarView(Activity activity, int color, int alpha) {
    // 绘制一个和状态栏一样高的矩形
    StatusBarView statusBarView = new StatusBarView(activity);
    LinearLayout.LayoutParams params =
            new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(activity));
    statusBarView.setLayoutParams(params);
    statusBarView.setBackgroundColor(calculateStatusColor(color, alpha));
    return statusBarView;
}
 
Example 12
Project: BrotherWeather   File: XStatusBar.java   View Source Code Vote up 5 votes
/**
 * 创建半透明矩形 View
 *
 * @param alpha 透明值
 * @return 半透明 View
 */
private static StatusBarView createTranslucentStatusBarView(Activity activity, int alpha) {
    // 绘制一个和状态栏一样高的矩形
    StatusBarView statusBarView = new StatusBarView(activity);
    LinearLayout.LayoutParams params =
            new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(activity));
    statusBarView.setLayoutParams(params);
    statusBarView.setBackgroundColor(Color.argb(alpha, 0, 0, 0));
    statusBarView.setId(FAKE_TRANSLUCENT_VIEW_ID);
    return statusBarView;
}
 
Example 13
Project: GravityBox   File: TrafficMeterAbstract.java   View Source Code Vote up 5 votes
protected TrafficMeterAbstract(Context context) {
    super(context);

    LinearLayout.LayoutParams lParams = new LinearLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
    mMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2,
            context.getResources().getDisplayMetrics());
    lParams.setMarginStart(mMargin);
    lParams.setMarginEnd(mMargin);
    setLayoutParams(lParams);
    setTextAppearance(context.getResources().getIdentifier(
            "TextAppearance.StatusBar.Clock", "style", PACKAGE_NAME));
    setGravity(Gravity.END | Gravity.CENTER_VERTICAL);

    if (!Utils.isWifiOnly(getContext())) {
        mPhone = (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE);
        mPhoneStateListener = new PhoneStateListener() {
            @Override
            public void onDataConnectionStateChanged(int state, int networkType) {
                final boolean connected = state == TelephonyManager.DATA_CONNECTED;
                if (mMobileDataConnected != connected) {
                    mMobileDataConnected = connected;
                    if (DEBUG)
                        log("onDataConnectionStateChanged: mMobileDataConnected=" + mMobileDataConnected);
                    updateState();
                }

            }
        };
    }
}
 
Example 14
Project: home-automation   File: DeviceActivity.java   View Source Code Vote up 5 votes
private void populate(final boolean enabled, List<DeviceActionDAO> defaultActions, List<StoryDeviceActionDAO> existingActions) {
    LinearLayout layout;
    if (enabled) {
        layout = findViewById(R.id.storyEnabledLinearLayout);
    } else {
        layout = findViewById(R.id.storyDisabledLinearLayout);
    }
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    lp.setMargins(0, 8, 0, 8);
    for (final DeviceActionDAO action : defaultActions) {
        Switch s = new Switch(this);
        s.setText(action.getName());
        s.setLayoutParams(lp);
        // Check the matching switch for every list
        for (StoryDeviceActionDAO existingAction : existingActions) {
            if (enabled && existingAction.isEnabled() && existingAction.getActionId() == action.getId()) {
                s.setChecked(true);
                break;
            } else if (!enabled && !existingAction.isEnabled() && existingAction.getActionId() == action.getId()) {
                s.setChecked(true);
                break;
            }
        }
        layout.addView(s);
        s.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
                if (checked) {
                    db.createActionForStoryAndDevice(storyId, enabled, action);
                } else {
                    db.deleteActionForStoryAndDevice(storyId, enabled, action);
                }
            }
        });
    }
}
 
Example 15
Project: getword   File: SnackbarUtil.java   View Source Code Vote up 5 votes
/**
 * 向Snackbar中添加view
 * @param snackbar
 * @param layoutId
 * @param index 新加布局在Snackbar中的位置
 */
public static void SnackbarAddView( Snackbar snackbar,int layoutId,int index) {
    View snackbarview = snackbar.getView();
    Snackbar.SnackbarLayout snackbarLayout=(Snackbar.SnackbarLayout)snackbarview;

    View add_view = LayoutInflater.from(snackbarview.getContext()).inflate(layoutId,null);

    LinearLayout.LayoutParams p = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    p.gravity= Gravity.CENTER_VERTICAL;

    snackbarLayout.addView(add_view,index,p);
}
 
Example 16
Project: topnews   File: EditPagePort.java   View Source Code Vote up 5 votes
private void initBottom(LinearLayout llBottom, float ratio) {
	LinearLayout llAt = new LinearLayout(activity);
	llAt.setPadding(0, 0, 0, 5);
	llAt.setBackgroundColor(0xffffffff);
	int bottomHeight = (int) (DESIGN_BOTTOM_HEIGHT * ratio);
	LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, bottomHeight);
	llBottom.addView(llAt, lp);

	tvAt = new TextView(activity);
	tvAt.setTextColor(0xff3b3b3b);
	tvAt.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22);
	tvAt.setGravity(Gravity.BOTTOM);
	tvAt.setText("@");
	int padding = (int) (DESIGN_LEFT_PADDING * ratio);
	tvAt.setPadding(padding, 0, padding, 0);
	lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
	llAt.addView(tvAt, lp);
	tvAt.setOnClickListener(this);
	if (isShowAtUserLayout(platform.getName())) {
		tvAt.setVisibility(View.VISIBLE);
	} else {
		tvAt.setVisibility(View.INVISIBLE);
	}

	tvTextCouter = new TextView(activity);
	tvTextCouter.setTextColor(0xff3b3b3b);
	tvTextCouter.setTextSize(TypedValue.COMPLEX_UNIT_SP, 21);
	tvTextCouter.setGravity(Gravity.BOTTOM | Gravity.RIGHT);
	onTextChanged(etContent.getText(), 0, 0, 0);
	tvTextCouter.setPadding(padding, 0, padding, 0);
	lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
	lp.weight = 1;
	llAt.addView(tvTextCouter, lp);

	View v = new View(activity);
	v.setBackgroundColor(0xffcccccc);
	int px1 = ratio > 1 ? ((int) ratio) : 1;
	lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, px1);
	llBottom.addView(v, lp);
}
 
Example 17
Project: Huochexing12306   File: XListViewFooter.java   View Source Code Vote up 4 votes
/**
 * show footer
 */
public void show() {
	LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams)mContentView.getLayoutParams();
	lp.height = LayoutParams.WRAP_CONTENT;
	mContentView.setLayoutParams(lp);
}
 
Example 18
Project: PlusGram   File: LayoutHelper.java   View Source Code Vote up 4 votes
public static LinearLayout.LayoutParams createLinear(int width, int height, int gravity) {
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(getSize(width), getSize(height));
    layoutParams.gravity = gravity;
    return layoutParams;
}
 
Example 19
Project: Hillffair17   File: EditorView.java   View Source Code Vote up 4 votes
public EditorView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);


    inflater = LayoutInflater.from(context);

    allLayout = new LinearLayout(context);
    allLayout.setOrientation(LinearLayout.VERTICAL);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    addView(allLayout, layoutParams);

    onClickListener = new OnClickListener() {
        @Override
        public void onClick(View view) {
            allLayout.removeView(view);
        }
    };

    focusChangeListener = new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean b) {
            if (b) {
                lastEditText = (EditText) view;
            }
        }
    };

    keyListener = new OnKeyListener() {
        @Override
        public boolean onKey(View view, int i, KeyEvent keyEvent) {
            if (keyEvent.getAction() == KeyEvent.ACTION_DOWN && keyEvent.getKeyCode() == KeyEvent.KEYCODE_DEL) {
                EditText editText = (EditText) view;
                onBackPress(editText);
            }
            return false;
        }
    };

    EditText e = createEditText("Title", dip2px(10));
    LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    allLayout.addView(e, p);

    EditText content = createEditText("Enter Description or Insert Any Image.\nSize of Description should be less than 200", dip2px(10));
    LinearLayout.LayoutParams contentp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    allLayout.addView(content, contentp
    );
    lastEditText = content;

}
 
Example 20
Project: TripleTap   File: SetGameCardView.java   View Source Code Vote up 4 votes
/**
 * Initialize our card with passed in attributes.
 *
 * @param context Context our view is in
 * @param attrs   Attributes passed into the constructor from code or the layout xml
 */
private void init(Context context, AttributeSet attrs) {

    // Get custom attributes
    TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.SetGameCardView);

    // Set some defaults
    mIsChecked = false;
    mIsHighlighted = false;

    try {
        mAspectRatioWidth = attributes.getInt(R.styleable.SetGameCardView_aspectWidth, 2);
        mAspectRatioHeight = attributes.getInt(R.styleable.SetGameCardView_aspectHeight, 3);

        // Defaults to Oval:Red:One:Solid if not set
        mShape = attributes.getInt(R.styleable.SetGameCardView_symbol_shape, 0);
        mColor = attributes.getInt(R.styleable.SetGameCardView_symbol_color, 0);
        mCount = attributes.getInt(R.styleable.SetGameCardView_symbol_count, 0);
        mFill = attributes.getInt(R.styleable.SetGameCardView_symbol_fill, 0);
    } finally {
        attributes.recycle();
    }

    /*
     * Set up 2D array to get the correct drawable based on shape and fill
     * +--------------------------------------------------+
     * | oval_solid     | oval_open     | oval_stripe     |
     * | diamond_solid  | diamond_open  | diamond_stripe  |
     * | squiggle_solid | squiggle_open | squiggle_stripe |
     * +--------------------------------------------------+
     */
    mShapeFill[0][0] = R.drawable.ic_set_icons_emerald_solid;
    mShapeFill[0][1] = R.drawable.ic_set_icons_emerald_open;
    mShapeFill[0][2] = R.drawable.ic_set_icons_emerald_stripe;
    mShapeFill[1][0] = R.drawable.ic_set_icons_diamond_solid;
    mShapeFill[1][1] = R.drawable.ic_set_icons_diamond_open;
    mShapeFill[1][2] = R.drawable.ic_set_icons_diamond_stripe;
    mShapeFill[2][0] = R.drawable.ic_set_icons_pear_solid;
    mShapeFill[2][1] = R.drawable.ic_set_icons_pear_open;
    mShapeFill[2][2] = R.drawable.ic_set_icons_pear_stripe;

    /*
     * Add a LinearLayout to the card's frame layout to hold the symbols
     */
    mLinearLayout = new LinearLayout(mContext);
    mLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
    mLinearLayout.setGravity(Gravity.CENTER);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT
    );
    mLinearLayout.setLayoutParams(layoutParams);
    this.setCardBackgroundColor(
            ContextCompat.getColor(getContext(), R.color.card_background_normal));
    this.addView(mLinearLayout);

    drawSymbols();
}