Java Code Examples for android.widget.TextView.setHeight()

The following are Jave code examples for showing how to use setHeight() of the android.widget.TextView 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: AnimationWrapLayout   File: MainActivity.java   View Source Code Vote up 6 votes
private TextView inflateTextView() {
    GradientDrawable shape = new GradientDrawable();
    shape.setCornerRadius(8);
    shape.setColor(0xff000000 | mRandom.nextInt(0x00ffffff));
    TextView textView = new TextView(this);
    textView.setGravity(Gravity.CENTER);
    textView.setTextColor(Color.WHITE);
    textView.setWidth(150 + mRandom.nextInt(3) * 50);
    textView.setHeight(150 + mRandom.nextInt(3) * 50);
    textView.setTextSize(32);
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
        textView.setBackgroundDrawable(shape);
    } else {
        textView.setBackground(shape);
    }
    textView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View view) {
            mList.removeViewWithAnimation(view);
        }
    });
    textView.setText(String.format(Locale.JAPAN, "%1$02d", mCounter++));
    return textView;
}
 
Example 2
Project: MainCalendar   File: DialogPicker.java   View Source Code Vote up 6 votes
@Override
@NonNull
protected LinearLayout makeCenterView() {
    LinearLayout rootLayout = new LinearLayout(activity);
    rootLayout.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
    rootLayout.setOrientation(LinearLayout.VERTICAL);

    mTextView = new TextView(activity);
    mTextView.setHeight(screenHeightPixels/4);
    mTextView.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
    mTextView.setGravity(Gravity.CENTER);
    mTextView.setTextSize(16);
    mTextView.setPadding(10, 10, 10, 10);
    mTextView.setText(mContent);
    rootLayout.addView(mTextView);

    setTitleText(mTitle);
    return rootLayout;
}
 
Example 3
Project: MovingGdufe-Android   File: ScheduleView.java   View Source Code Vote up 6 votes
private View addStartView(int startnum, final int week, final int start) {
        LinearLayout mStartView = new LinearLayout(getContext());
        mStartView.setOrientation(VERTICAL);
        for (int i = 1; i < startnum; i++) {
            TextView mTime = new TextView(getContext());
            mTime.setGravity(Gravity.CENTER);
            mTime.setHeight(dip2px(TimeTableHeight));
            mTime.setWidth(dip2px(TimeTableHeight));
            mStartView.addView(mTime);
            mStartView.addView(getWeekTransverseLine());

            //这里可以处理空白处点击添加课表
            final int finalI = i;
            mTime.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
//                    Toast.makeText(getContext(), "星期" + week + "第" + (start + num) + "节", Toast.LENGTH_SHORT).show();
                    //TODO 添加课程
                    mClickListener.onClickScheduleAdd(week,start+ finalI);
                }
            });

        }
        return mStartView;
    }
 
Example 4
Project: zero-to-app-emojistories   File: StoryAdapter.java   View Source Code Vote up 6 votes
public void addEmoji(List<String> emojis, String storyId) {
    String storyIdMessage = storyId + "-message";
    storyId += "-emoji";

    removeStuffWithThisKey(storyIdMessage);
    removeStuffWithThisKey(storyId);

    int gridThingPixels = (int) myContext.getResources().getDimension(R.dimen.grid_thing);

    for (String emoji : emojis) {
        TextView textThing = new TextView(myContext);
        textThing.setText(emoji);
        textThing.setTextSize(60);
        textThing.setHeight(gridThingPixels);

        gridContents.add(new TaggedView(textThing, storyId));
    }

    this.notifyDataSetChanged();
}
 
Example 5
Project: TrackIt-Android   File: MainActivity.java   View Source Code Vote up 5 votes
private void displaySnackbar(String snackbarText) {
    Snackbar snackbar = Snackbar.make(relativeLayout, snackbarText, Snackbar.LENGTH_LONG);
    View view = snackbar.getView();
    TextView textView = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
    textView.setHeight(mTabLayout.getHeight());
    textView.setGravity(Gravity.CENTER_VERTICAL);
    snackbar.show();
}
 
Example 6
Project: editor-sql   File: Utils.java   View Source Code Vote up 5 votes
public static Point MeasureString(Context context, String text, float fontSize, int widthMeasureSpec, int heightMeasureSpec) {
    int width = 0;
    int height = 0;

    if (null == context || null == text || text.isEmpty() || 0 == fontSize) {
        return null;
    }

    TextView tv = new TextView(context);

    tv.setText(text);// 待测文本
    tv.setTextSize(fontSize);// 字体

    if (ViewGroup.LayoutParams.WRAP_CONTENT != widthMeasureSpec && ViewGroup.LayoutParams.MATCH_PARENT != widthMeasureSpec) {
        tv.setWidth(widthMeasureSpec);// 如果设置了宽度,字符串的宽度则为所设置的宽度
    }

    if (ViewGroup.LayoutParams.WRAP_CONTENT != heightMeasureSpec && ViewGroup.LayoutParams.MATCH_PARENT != heightMeasureSpec) {
        tv.setHeight(heightMeasureSpec);
    }

    tv.setSingleLine(false);// 多行

    tv.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);

    width = tv.getMeasuredWidth();
    height = tv.getMeasuredHeight();

    Point point = new Point();
    point.x = width;
    point.y = height;

    return point;
}
 
Example 7
Project: MovingGdufe-Android   File: ScheduleView.java   View Source Code Vote up 5 votes
/**
 * 横的分界线
 *
 * @return
 */
private View getWeekTransverseLine() {
    TextView mWeekline = new TextView(getContext());
    mWeekline.setBackgroundColor(getResources().getColor(R.color.view_line));
    mWeekline.setHeight(TimeTableLineHeight);
    mWeekline.setWidth(LayoutParams.FILL_PARENT);
    return mWeekline;
}
 
Example 8
Project: MovingGdufe-Android   File: ScheduleView.java   View Source Code Vote up 5 votes
/**
 * 竖向分界线
 *
 * @return
 */
private View getWeekVerticalLine() {
    TextView mWeekline = new TextView(getContext());
    mWeekline.setBackgroundColor(getResources().getColor(R.color.view_line));
    mWeekline.setHeight(dip2px(TimeTableWeekNameHeight));
    mWeekline.setWidth((TimeTableLineHeight));
    return mWeekline;
}
 
Example 9
Project: MovingGdufe-Android   File: ScheduleView.java   View Source Code Vote up 5 votes
/**
     * 获取单个课表View
     *
     * @param model 数据类型
     * @return
     */
    @SuppressWarnings("deprecation")
    private View getMode(final Schedule model) {
        LinearLayout mScheduleView = new LinearLayout(getContext());
        mScheduleView.setOrientation(VERTICAL);
        TextView mTimeTableNameView = new TextView(getContext());
        int num = model.getEndSec() - model.getStartSec();
        mTimeTableNameView.setHeight(dip2px((num + 1) * TimeTableHeight) + num * 2);
        mTimeTableNameView.setTextColor(getContext().getResources().getColor(
                android.R.color.white));
        mTimeTableNameView.setWidth(dip2px(50));
        mTimeTableNameView.setTextSize(CourseTextSize);
        mTimeTableNameView.setGravity(Gravity.CENTER);
        mTimeTableNameView.setText(model.getName() + "\n" + model.getLocation());
        mScheduleView.addView(mTimeTableNameView);
        mScheduleView.addView(getWeekTransverseLine());
        mScheduleView.setBackgroundDrawable(getContext().getResources()
                .getDrawable(colors[getColorNum(model.getName())]));

        if(mCurrentWeek != FileUtils.SP_WEEK_NOT_SET && !CalcUtils.isCurrentWeek(model.getPeriod(), mCurrentWeek)){
            mScheduleView.setBackgroundDrawable(getContext().getResources()
                    .getDrawable(notGocolors));
//            mTimeTableNameView.setTextColor(getContext().getResources().getColor(
//                    android.R.color.darker_gray));
        }

        mScheduleView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
//                Toast.makeText(getContext(), model.getName() + "\n" + model.getLocation()+"\n" +model.getPeriod()+"\n"+ model.getTeacher(), Toast.LENGTH_SHORT).show();
                //TODO 编辑课程
                mClickListener.onClickScheduleEdit(model);
            }
        });
        return mScheduleView;
    }
 
Example 10
Project: TitanCompanion   File: SSAdventureMapFragment.java   View Source Code Vote up 5 votes
public void setClearingLayoutSizes(View rootView, Context context) {

        DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
        float dpHeight = displayMetrics.heightPixels / displayMetrics.density;
        float dpWidth = displayMetrics.widthPixels / displayMetrics.density;

        dpHeight -= addClearingButton.getHeight();

        dpHeight /= 9;
        dpWidth /= 7;


        int finalValue = (int) Math.min(dpHeight, dpWidth);

        TableLayout table = rootView.findViewById(R.id.clearingGrid);
        final int childcount = table.getChildCount();
        for (int i = 0; i < childcount; i++) {
            TableRow row = (TableRow) table.getChildAt(i);

            final int cellCount = row.getChildCount();
            for (int j = 0; j < cellCount; j++) {
                TextView cell = (TextView) row.getChildAt(j);
                cell.setHeight(finalValue);
                cell.setWidth(finalValue);
            }


        }
    }
 
Example 11
Project: PWEditText-SafeKeyboard   File: SafetyKeyboard.java   View Source Code Vote up 4 votes
/**
 * 密码键盘默认样式
 * @param context
 */
private void initView(Context context) {
    mkeyboardLayout = new LinearLayout(context);
    mkeyboardLayout.setOrientation(LinearLayout.VERTICAL);
    if (null != mKeyBoardBgDrawable) {
        mkeyboardLayout.setBackgroundDrawable(mKeyBoardBgDrawable);
    } else {
        mkeyboardLayout.setBackgroundColor(Color.GRAY);
    }
    LinearLayout.LayoutParams titleParams = new LinearLayout.LayoutParams(
            LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    titleParams.setMargins(0, 0, 0, 6);
    mTitleLayout = new LinearLayout(context);
    mTitleLayout.setGravity(Gravity.CENTER);
    mTitleLayout.setOrientation(LinearLayout.HORIZONTAL);

    mTitleLayout.setLayoutParams(titleParams);
    int titleBackgroundColor = mContext.getResources()
            .getColor(R.color.bg_security_keyboard_title);
    mTitleLayout.setBackgroundColor(titleBackgroundColor);
    mTitleView = new TextView(context);
    mTitleView.setText("Secure Mode");
    mTitleView.setTextColor(Color.WHITE);
    mTitleView.setHeight(getSaftyKeyHeight() / 16);
    mTitleView.setGravity(Gravity.CENTER);
    mTitleLayout.addView(mTitleView);

    mKeyBoardControl = new GrapeGridview(context);
    mKeyBoardControl.setHorizontalScrollBarEnabled(false);
    mKeyBoardControl.setVerticalScrollBarEnabled(false);
    mKeyBoardControl.setEnabled(false);
    mKeyBoardControl.setNumColumns(Constant.COLUMN_SOFT_KEYBOARD);
    mKeyBoardControl.setVerticalSpacing(mMarginRow);
    mKeyBoardControl.setHorizontalSpacing(mMarginCol);
    mKeyBoardControl.setAdapter(mAdapter);

    mkeyboardLayout.addView(mTitleLayout);
    mkeyboardLayout.addView(mKeyBoardControl);
    mkeyboardLayout.setPadding(mPaddingLeft, mPaddingTop, mPaddingRight,
            mPaddingBottom);

    mPopup = new PopupWindow(mkeyboardLayout, mWidth, mHeight);
    mPopup.setBackgroundDrawable(new BitmapDrawable());
    mPopup.setSoftInputMode(
            WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
    mPopup.setOutsideTouchable(true);
    mPopup.setFocusable(true);
    mPopup.setOnDismissListener(dismissListener);
}
 
Example 12
Project: SmartChart   File: PanelListAdapter.java   View Source Code Vote up 4 votes
/**
 * 初始化横向表头的布局,必须在所有的布局都载入完之后才能调用
 * <p>
 * must be called in pl_root.post();
 */
private void initRowLayout() {

    if (rowDataList == null) {
        Log.e("PanelList", "custom Row data list is strongly recommended! Call setRowDataList(List<String> rowDataList) in your panel adapter");
    }
    int rowCount = ll_contentItem.getChildCount();

    List<String> rowDataList1 = getRowDataList(rowCount);

    //分隔线的设置,如果content的item设置了分割线,那row使用相同的分割线,除非单独给row设置了分割线
    ll_row.setBackgroundColor(Color.parseColor(rowColor));
    if (rowDivider == null) {
        ll_row.setDividerDrawable(ll_contentItem.getDividerDrawable());
    } else {
        ll_row.setDividerDrawable(rowDivider);
    }

    // 获得row一共有多少个item,然后使用循环往里面添加对应个数个TextView(简单粗暴)
    for (int i = 0; i < rowCount; i++) {
        View contentItem = ll_contentItem.getChildAt(i);// 获得item的item,以便获取宽度
        TextView rowItem = new TextView(context);
        rowItem.setText(rowDataList1.get(i));//设置文字
        Paint rowPaint=rowItem.getPaint();
        rowPaint.setFakeBoldText(false);
        rowPaint.setColor(context.getResources().getColor(R.color.color_646464));
        rowPaint.setTextSize(CommonUtils.dp2px(context,15));
        rowItem.setWidth(contentItem.getWidth()-2);//设置宽度
        rowItem.setHeight(titleHeight);//设置高度
        rowItem.setGravity(Gravity.CENTER);
        TextView line=new TextView(context);
        ll_row.addView(rowItem);
        if (i<rowCount-1){
            line.setBackgroundColor(Color.WHITE);
            line.setWidth(2);
            line.setHeight(titleHeight);
            ll_row.addView(line);
        }


    }
}
 
Example 13
Project: Matrix-Calculator-for-Android   File: ViewMatrixFragment.java   View Source Code Vote up 4 votes
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    int index = getArguments().getInt("INDEX");

    View v = inflater.inflate(R.layout.view_matrix_frag, container, false);
    CardView cardView = (CardView) v.findViewById(R.id.DynamicCardView);

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
    String string = sharedPreferences.getString("ELEVATE_AMOUNT", "4");
    String string2 = sharedPreferences.getString("CARD_CHANGE_KEY", "#bdbdbd");

    cardView.setCardElevation(Integer.parseInt(string));
    cardView.setCardBackgroundColor(Color.parseColor(string2));

    CardView.LayoutParams params1 = new CardView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);

    GridLayout gridLayout = new GridLayout(getContext());
    gridLayout.setRowCount(((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetRow());
    gridLayout.setColumnCount(((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetCol());
    for (int i = 0; i < ((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetRow(); i++) {
        for (int j = 0; j < ((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetCol(); j++) {
            TextView textView = new TextView(getContext());
            textView.setGravity(Gravity.CENTER);
            textView.setText(SafeSubString(GetText(((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetElementof(i, j)), getLength()));
            textView.setWidth(CalculatedWidth(((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetCol()));
            textView.setTextSize(SizeReturner(((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetRow(), ((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetCol(),
                    PreferenceManager.getDefaultSharedPreferences(getContext()).
                            getBoolean("EXTRA_SMALL_FONT", false)));
            textView.setHeight(CalculatedHeight(((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetRow()));
            GridLayout.Spec Row = GridLayout.spec(i, 1);
            GridLayout.Spec Col = GridLayout.spec(j, 1);
            GridLayout.LayoutParams params = new GridLayout.LayoutParams(Row, Col);
            gridLayout.addView(textView, params);
        }
    }
    gridLayout.setLayoutParams(params1);
    cardView.addView(gridLayout);


    // Inflate the layout for this fragment
    return v;
}
 
Example 14
Project: Matrix-Calculator-for-Android   File: MinorChooserFragment.java   View Source Code Vote up 4 votes
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    final int index = getArguments().getInt("INDEX");

    View v = inflater.inflate(R.layout.view_matrix_frag, container, false);
    CardView cardView = (CardView) v.findViewById(R.id.DynamicCardView);

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
    String string = sharedPreferences.getString("ELEVATE_AMOUNT", "4");
    String string2 = sharedPreferences.getString("CARD_CHANGE_KEY", "#bdbdbd");

    cardView.setCardElevation(Integer.parseInt(string));
    cardView.setCardBackgroundColor(Color.parseColor(string2));

    CardView.LayoutParams params1 = new CardView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);

    GridLayout gridLayout = new GridLayout(getContext());
    gridLayout.setRowCount(((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetRow());
    gridLayout.setColumnCount(((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetCol());
    for (int i = 0; i < ((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetRow(); i++) {
        for (int j = 0; j < ((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetCol(); j++) {
            final TextView textView = new TextView(getContext());
            textView.setGravity(Gravity.CENTER);
            textView.setTag(i * 10 + j);
            textView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    textView.setTypeface(textView.getTypeface(), Typeface.BOLD);
                    final ProgressDialog progressDialog = new ProgressDialog(getContext());
                    progressDialog.setIndeterminate(false);
                    progressDialog.setMessage(getString(R.string.Calculating));
                    progressDialog.setProgress(ProgressDialog.STYLE_SPINNER);
                    progressDialog.setTitle(getString(R.string.Calculating));
                    progressDialog.show();
                    Runnable runnable = new Runnable() {
                        @Override
                        public void run() {
                            float res = ((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetMinorDeterminant(((int) textView.getTag()) / 10, ((int) textView.getTag()) % 10);
                            Message message = new Message();
                            Bundle bundle = new Bundle();
                            bundle.putInt("REX", ((int) textView.getTag()) / 10);
                            bundle.putInt("REY", ((int) textView.getTag()) % 10);
                            bundle.putFloat("VALUE", res);
                            message.setData(bundle);
                            progressDialog.dismiss();
                            handler.sendMessage(message);
                        }
                    };
                    Thread thread = new Thread(runnable);
                    thread.start();
                }
            });
            textView.setText(SafeSubString(GetText(((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetElementof(i, j)), getLenght()));
            textView.setWidth(CalculatedWidth(((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetCol()));
            textView.setTextSize(SizeReturner(((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetRow(), ((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetCol(),
                    PreferenceManager.getDefaultSharedPreferences(getContext()).
                            getBoolean("EXTRA_SMALL_FONT", false)));
            textView.setHeight(CalculatedHeight(((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetRow()));
            GridLayout.Spec Row = GridLayout.spec(i, 1);
            GridLayout.Spec Col = GridLayout.spec(j, 1);
            GridLayout.LayoutParams params = new GridLayout.LayoutParams(Row, Col);
            gridLayout.addView(textView, params);
        }
    }
    gridLayout.setLayoutParams(params1);
    cardView.addView(gridLayout);

    // Inflate the layout for this fragment
    return v;

}
 
Example 15
Project: sealtalk-android-master   File: ReadReceiptDetailActivity.java   View Source Code Vote up 4 votes
private void setTabSelectedBG(TextView vLine, TextView vText) {
    vLine.setBackgroundColor(getResources().getColor(R.color.ac_filter_string_color));
    vLine.setHeight(6);
    vText.setTextColor(getResources().getColor(R.color.ac_filter_string_color));
}
 
Example 16
Project: sealtalk-android-master   File: ReadReceiptDetailActivity.java   View Source Code Vote up 4 votes
private void setTabUnSelectedBG(TextView vLine, TextView vText) {
    vLine.setBackgroundColor(getResources().getColor(R.color.text_line_color));
    vLine.setHeight(1);
    vText.setTextColor(getResources().getColor(R.color.text_color));
}
 
Example 17
Project: zero-to-app-emojistories   File: StoryAdapter.java   View Source Code Vote up 4 votes
public void addMessage(String message, String storyId) {
    storyId += "-message";

    removeStuffWithThisKey(storyId);

    TextView textThing = new TextView(myContext);
    textThing.setText(message);
    textThing.setTextSize(25);

    int gridThingPixels = (int) myContext.getResources().getDimension(R.dimen.grid_thing);
    textThing.setHeight(gridThingPixels);

    gridContents.add(new TaggedView(textThing, storyId));

    this.notifyDataSetChanged();
}
 
Example 18
Project: rongyunDemo   File: ReadReceiptDetailActivity.java   View Source Code Vote up 4 votes
private void setTabSelectedBG(TextView vLine, TextView vText) {
    vLine.setBackgroundColor(getResources().getColor(R.color.ac_filter_string_color));
    vLine.setHeight(6);
    vText.setTextColor(getResources().getColor(R.color.ac_filter_string_color));
}
 
Example 19
Project: rongyunDemo   File: ReadReceiptDetailActivity.java   View Source Code Vote up 4 votes
private void setTabUnSelectedBG(TextView vLine, TextView vText) {
    vLine.setBackgroundColor(getResources().getColor(R.color.text_line_color));
    vLine.setHeight(1);
    vText.setTextColor(getResources().getColor(R.color.text_color));
}