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

The following are Jave code examples for showing how to use getLayoutParams() 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: GitHub   File: MinorAdapter.java   View Source Code Vote up 6 votes
@Override
public void convert(EasyLVHolder holder, int position, String s) {
    holder.setText(R.id.tvMinorItem, s);

    if (current == position) {
        holder.setVisible(R.id.ivMinorChecked, true);
    } else {
        holder.setVisible(R.id.ivMinorChecked, false);
    }

    if (position != 0) { // 子项右移
        TextView textView = holder.getView(R.id.tvMinorItem);
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) textView.getLayoutParams();
        params.leftMargin = ScreenUtils.dpToPxInt(25);
        textView.setLayoutParams(params);
    }
}
 
Example 2
Project: EsperantoRadio   File: PagerSlidingTabStrip.java   View Source Code Vote up 6 votes
private void addIconTabBådeTekstOgBillede(final int position, int resId, String url, String title) {
  FrameLayout tabfl = new FrameLayout(getContext());
  ImageView tabi = new ImageView(getContext());
  tabi.setContentDescription(title);
  //Log.d(title+" "+resId + " Kanallogo URL="+url);
  if (resId==0) {
    Picasso.with(tabi.getContext())
            .load(url).placeholder(null)
            .into(tabi);

    tabi.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    tabi.setAdjustViewBounds(true);
    tabi.setVisibility(View.GONE);
  } else {
    tabi.setImageResource(resId);
    tabi.setVisibility(View.INVISIBLE);
  }
  TextView tabt = new TextView(getContext());
  tabt.setText(title);
  tabt.setTypeface(App.skrift_gibson);
  tabt.setGravity(Gravity.CENTER);
  tabt.setSingleLine();

  tabfl.addView(tabi);
  tabfl.addView(tabt);

  LayoutParams lp = (LayoutParams) tabi.getLayoutParams();
  lp.gravity=Gravity.CENTER;
  lp.width=lp.height=ViewGroup.LayoutParams.MATCH_PARENT;
  lp = (LayoutParams) tabt.getLayoutParams();
  lp.width=lp.height=ViewGroup.LayoutParams.MATCH_PARENT;
  lp.gravity=Gravity.CENTER;

  addTab(position, tabfl);
}
 
Example 3
Project: CustomSpinner   File: CustomSpinner.java   View Source Code Vote up 6 votes
private void initView() {
    mRlSpinner = (RelativeLayout) findViewById(R.id.rl_spinner);
    mTvSelected = (TextView) findViewById(R.id.tv_selected);
    mIvIndicate = (ImageView) findViewById(R.id.iv_indicate);

    RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) mTvSelected.getLayoutParams();
    RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mIvIndicate.getLayoutParams();
    params1.leftMargin = mLeftMargin;
    params2.rightMargin = mRightMargin;

    mRlSpinner.setBackgroundResource(R.drawable.solid_tran_stroke_gray);
    mTvSelected.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
    mTvSelected.setTextColor(mTextColor);

    this.setOnClickListener(this);
}
 
Example 4
Project: CustomAndroidOneSheeld   File: SpeechRecognitionFragment.java   View Source Code Vote up 6 votes
@Override
public void doOnViewCreated(View v, @Nullable Bundle savedInstanceState) {
    statusCircle = v.findViewById(R.id.statusCircle);
    statusHint = (OneSheeldTextView) v.findViewById(R.id.statusHint);
    rmsIndicator = (TextView) v.findViewById(R.id.rmsLevelIndicator);
    recognizedResult = (OneSheeldTextView) v
            .findViewById(R.id.recognizedResult);
    params = (LayoutParams) rmsIndicator.getLayoutParams();
    statusCircle.getViewTreeObserver().addOnGlobalLayoutListener(
            new ViewTreeObserver.OnGlobalLayoutListener() {

                @Override
                public void onGlobalLayout() {
                    if (stepValue == 0)
                        stepValue = statusCircle.getHeight() / 10;
                }
            });
}
 
Example 5
Project: ScrollableNumberPicker   File: ScrollableNumberPicker.java   View Source Code Vote up 6 votes
private void initValueView() {
    mValueTextView = (TextView) findViewById(R.id.text_value);

    if (mValueTextAppearanceResId != INVALID_RES) {
        TextViewCompat.setTextAppearance(mValueTextView, mValueTextAppearanceResId);
    }

    if (mValueTextColor != 0) {
        mValueTextView.setTextColor(mValueTextColor);
    }

    if (mValueTextSize != INVALID_RES) {
        mValueTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mValueTextSize);
    }

    LinearLayout.LayoutParams layoutParams = (LayoutParams) mValueTextView.getLayoutParams();
    if (mOrientation == HORIZONTAL) {
        layoutParams.setMargins(mValueMarginStart, 0, mValueMarginEnd, 0);
    } else {
        layoutParams.setMargins(0, mValueMarginStart, 0, mValueMarginEnd);
    }

    mValueTextView.setLayoutParams(layoutParams);

    setValue();
}
 
Example 6
Project: leoapp-sources   File: ScanActivity.java   View Source Code Vote up 6 votes
@Override
public void onCreate(Bundle b) {
    getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
    super.onCreate(b);
    setContentView(R.layout.activity_scanqr);

    initToolbar();
    initNavigationBar();

    barcodeScannerView = findViewById(R.id.qrcode_view);

    TextView tooltip = findViewById(R.id.tooltip);
    tooltip.setText("Platziere den QR-Code innerhalb des Rechtecks");
    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) tooltip.getLayoutParams();
    params.setMargins(0, 0, 0, GraphicUtils.getDisplayHeight()/4);
    tooltip.setLayoutParams(params);

    capture = new CaptureManager(this, barcodeScannerView);
    capture.initializeFromIntent(getIntent(), b);
    capture.decode();
}
 
Example 7
Project: CustomAndroidOneSheeld   File: MicFragment.java   View Source Code Vote up 6 votes
@Override
public void doOnViewCreated(View v, @Nullable Bundle savedInstanceState) {
    soundLevelIndicator = (TextView) v
            .findViewById(R.id.soundLevelIndicator);
    micValue = (OneSheeldTextView) v.findViewById(R.id.micValue);
    micState = (OneSheeldTextView) v.findViewById(R.id.micState);
    params = (LayoutParams) soundLevelIndicator.getLayoutParams();
    soundLevelIndicator.getViewTreeObserver().addOnGlobalLayoutListener(
            new ViewTreeObserver.OnGlobalLayoutListener() {

                @Override
                public void onGlobalLayout() {
                    stepValue = soundLevelIndicator.getHeight() / 80;
                }
            });
}
 
Example 8
Project: TextReader   File: MinorAdapter.java   View Source Code Vote up 6 votes
@Override
public void convert(EasyLVHolder holder, int position, String s) {
    holder.setText(R.id.tvMinorItem, s);

    if (current == position) {
        holder.setVisible(R.id.ivMinorChecked, true);
    } else {
        holder.setVisible(R.id.ivMinorChecked, false);
    }

    if (position != 0) { // 子项右移
        TextView textView = holder.getView(R.id.tvMinorItem);
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) textView.getLayoutParams();
        params.leftMargin = ScreenUtils.dpToPxInt(25);
        textView.setLayoutParams(params);
    }
}
 
Example 9
Project: PlusGram   File: SlidingTabView.java   View Source Code Vote up 6 votes
public void addTextTab(final int position, String title) {
    TextView tab = new TextView(getContext());
    tab.setText(title);
    tab.setFocusable(true);
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();
    tab.setTextColor(0xffffffff);
    tab.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    tab.setTypeface(Typeface.DEFAULT_BOLD);
    tab.setBackgroundDrawable(Theme.createBarSelectorDrawable(Theme.ACTION_BAR_PICKER_SELECTOR_COLOR, false));

    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            didSelectTab(position);
        }
    });
    addView(tab);
    LayoutParams layoutParams = (LayoutParams)tab.getLayoutParams();
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    layoutParams.width = 0;
    layoutParams.weight = 50;
    tab.setLayoutParams(layoutParams);

    tabCount++;
}
 
Example 10
Project: Kandroid   File: ProjectTaskAdapter.java   View Source Code Vote up 6 votes
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
    KanboardSwimlane swimlane = (KanboardSwimlane) getGroup(groupPosition);

    if (convertView == null)
        convertView = mInflater.inflate(R.layout.listitem_dash_project_header, parent, false);

    TextView projectName = (TextView) convertView.findViewById(R.id.project_name);
    TextView projectDescription = (TextView) convertView.findViewById(R.id.project_description);
    TextView projectColumns = (TextView) convertView.findViewById(R.id.project_columns);
    TextView projectNbTasks = (TextView) convertView.findViewById(R.id.project_nb_own_tasks);
    TextView sidebar = (TextView) convertView.findViewById(R.id.sidebar);

    projectName.setText(swimlane.getName());
    int taskCount = mData.get(swimlane.getId()).size();
    projectNbTasks.setText(mContext.getResources().getQuantityString(R.plurals.format_nb_tasks, taskCount, taskCount));
    RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) sidebar.getLayoutParams();
    lp.removeRule(RelativeLayout.ALIGN_BOTTOM);
    projectDescription.setText(swimlane.getDescription() == null ? "" : swimlane.getDescription());
    lp.addRule(RelativeLayout.ALIGN_BOTTOM, projectDescription.getId());
    sidebar.setLayoutParams(lp);
    projectColumns.setVisibility(View.GONE);

    return convertView;
}
 
Example 11
Project: GitHub   File: BadgeItem.java   View Source Code Vote up 5 votes
/**
 * @param gravity gravity of badge (TOP|LEFT ..etc)
 * @return this, to allow builder pattern
 */
public T setGravity(int gravity) {
    this.mGravity = gravity;
    if (isWeakReferenceValid()) {
        TextView textView = mTextViewRef.get();
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) textView.getLayoutParams();
        layoutParams.gravity = gravity;
        textView.setLayoutParams(layoutParams);
    }
    return getSubInstance();
}
 
Example 12
Project: GitHub   File: BaseViewHolder.java   View Source Code Vote up 5 votes
protected RelativeLayout.LayoutParams getParamsLayout(TextView layout, T itemData) {
    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) layout.getLayoutParams();
    params.leftMargin = itemMargin * itemData.getTreeDepth();
    //    layout.setLayoutParams();
    return params;
    //   layout.setMar
}
 
Example 13
Project: AdaptationX-android   File: TextViewManager.java   View Source Code Vote up 5 votes
/**
 * 在某些特定场合下; TextView 的 wrap_content 属性不生效;只好手动设置
 * @param textView
 * @param tvWidth textView 在屏幕上显示的宽(也就是 textView 父容器赐予的最大宽)
 */
public static void setTvWrapHeight(TextView textView,int tvWidth){
    textView.measure(0,0);
    int height = textView.getMeasuredHeight();
    ViewGroup.LayoutParams params = textView.getLayoutParams();
    params.height = height * getRow(textView, tvWidth) ;
    textView.setLayoutParams(params);
}
 
Example 14
Project: RecycylerViewItemDecoration   File: RecyclerViewStaggeredAdapter.java   View Source Code Vote up 5 votes
public RecyclerViewVH(View itemView) {
    super(itemView);
    textView = (TextView) itemView;
    ViewGroup.LayoutParams params = textView.getLayoutParams();
    params.height = (int) (200 + Math.random() * 400);
    textView.setLayoutParams(params);
}
 
Example 15
Project: airgram   File: SlidingTabView.java   View Source Code Vote up 5 votes
public void addTextTab(final int position, String title) {
    TextView tab = new TextView(getContext());
    tab.setTypeface(FontManager.instance().getTypeface());
    tab.setText(title);
    tab.setFocusable(true);
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();
    tab.setTextColor(0xffffffff);
    tab.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    tab.setTypeface(Typeface.DEFAULT_BOLD);
    tab.setBackgroundDrawable(Theme.createBarSelectorDrawable(Theme.ACTION_BAR_PICKER_SELECTOR_COLOR, false));

    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            didSelectTab(position);
        }
    });
    addView(tab);
    LayoutParams layoutParams = (LayoutParams)tab.getLayoutParams();
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    layoutParams.width = 0;
    layoutParams.weight = 50;
    tab.setLayoutParams(layoutParams);

    tabCount++;
}
 
Example 16
Project: number-keyboard   File: NumberKeyboard.java   View Source Code Vote up 5 votes
/**
 * Sets key width in px.
 */
public void setKeyWidth(int px) {
    for (TextView key : numericKeys) {
        key.getLayoutParams().width = px;
    }
    leftAuxBtn.getLayoutParams().width = px;
    rightAuxBtn.getLayoutParams().width = px;
    requestLayout();
}
 
Example 17
Project: number-keyboard   File: NumberKeyboard.java   View Source Code Vote up 5 votes
/**
 * Sets key height in px.
 */
public void setKeyHeight(int px) {
    for (TextView key : numericKeys) {
        key.getLayoutParams().height = px;
    }
    leftAuxBtn.getLayoutParams().height = px;
    rightAuxBtn.getLayoutParams().height = px;
    requestLayout();
}
 
Example 18
Project: Ucount   File: IOItemAdapter.java   View Source Code Vote up 5 votes
public void handleDescription(IOItem ioItem, TextView Dsp, TextView Name, TextView Money) {
    if (isThereADescription(ioItem)) {
        RelativeLayout.LayoutParams nameParams = (RelativeLayout.LayoutParams)Name.getLayoutParams();
        nameParams.removeRule(RelativeLayout.CENTER_VERTICAL);
        RelativeLayout.LayoutParams moneyParams = (RelativeLayout.LayoutParams)Money.getLayoutParams();
        moneyParams.removeRule(RelativeLayout.CENTER_VERTICAL);
        Dsp.setText(ioItem.getDescription());
        Name.setLayoutParams(nameParams);
        Money.setLayoutParams(moneyParams);
    } else {
        Dsp.setVisibility(View.GONE);
    }
}
 
Example 19
Project: DailyStudy   File: WxItemDecoration.java   View Source Code Vote up 5 votes
private void drawInflat(Canvas c, RecyclerView parent, String tag) {
    TextView toDrawView = (TextView) LayoutInflater.from(parent.getContext()).inflate(R.layout.title_item, parent, false);
    toDrawView.setText(tag);
    int toDrawWidthSpec;//用于测量的widthMeasureSpec
    int toDrawHeightSpec;//用于测量的heightMeasureSpec
    //拿到复杂布局的LayoutParams,如果为空,就new一个。
    // 后面需要根据这个lp 构建toDrawWidthSpec,toDrawHeightSpec
    ViewGroup.LayoutParams lp = toDrawView.getLayoutParams();
    if (lp == null) {
        lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);//这里是根据复杂布局layout的width height,new一个Lp
        toDrawView.setLayoutParams(lp);
    }
    if (lp.width == ViewGroup.LayoutParams.MATCH_PARENT) {
        //如果是MATCH_PARENT,则用父控件能分配的最大宽度和EXACTLY构建MeasureSpec。
        toDrawWidthSpec = View.MeasureSpec.makeMeasureSpec(parent.getWidth() - parent.getPaddingLeft() - parent.getPaddingRight(), View.MeasureSpec.EXACTLY);
    } else if (lp.width == ViewGroup.LayoutParams.WRAP_CONTENT) {
        //如果是WRAP_CONTENT,则用父控件能分配的最大宽度和AT_MOST构建MeasureSpec。
        toDrawWidthSpec = View.MeasureSpec.makeMeasureSpec(parent.getWidth() - parent.getPaddingLeft() - parent.getPaddingRight(), View.MeasureSpec.AT_MOST);
    } else {
        //否则则是具体的宽度数值,则用这个宽度和EXACTLY构建MeasureSpec。
        toDrawWidthSpec = View.MeasureSpec.makeMeasureSpec(lp.width, View.MeasureSpec.EXACTLY);
    }
    //高度同理
    if (lp.height == ViewGroup.LayoutParams.MATCH_PARENT) {
        toDrawHeightSpec = View.MeasureSpec.makeMeasureSpec(parent.getHeight() - parent.getPaddingTop() - parent.getPaddingBottom(), View.MeasureSpec.EXACTLY);
    } else if (lp.height == ViewGroup.LayoutParams.WRAP_CONTENT) {
        toDrawHeightSpec = View.MeasureSpec.makeMeasureSpec(parent.getHeight() - parent.getPaddingTop() - parent.getPaddingBottom(), View.MeasureSpec.AT_MOST);
    } else {
        toDrawHeightSpec = View.MeasureSpec.makeMeasureSpec(lp.width, View.MeasureSpec.EXACTLY);
    }
    //依次调用 measure,layout,draw方法,将复杂头部显示在屏幕上。
    toDrawView.measure(toDrawWidthSpec, toDrawHeightSpec);
    toDrawView.layout(parent.getPaddingLeft(), parent.getPaddingTop(),
            parent.getPaddingLeft() + toDrawView.getMeasuredWidth(), parent.getPaddingTop() + toDrawView.getMeasuredHeight());
    toDrawView.draw(c);
}
 
Example 20
Project: KrGallery   File: ActionBarMenuItem.java   View Source Code Vote up 4 votes
public TextView addSubItem(int id, String text, int icon) {
    if (popupLayout == null) {
        rect = new Rect();
        location = new int[2];
        popupLayout = new ActionBarPopupWindow.ActionBarPopupWindowLayout(getContext());
        popupLayout.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
                    if (popupWindow != null && popupWindow.isShowing()) {
                        v.getHitRect(rect);
                        if (!rect.contains((int) event.getX(), (int) event.getY())) {
                            popupWindow.dismiss();
                        }
                    }
                }
                return false;
            }
        });
        popupLayout.setDispatchKeyEventListener(new ActionBarPopupWindow.OnDispatchKeyEventListener() {
            @Override
            public void onDispatchKeyEvent(KeyEvent keyEvent) {
                if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_BACK && keyEvent.getRepeatCount() == 0 && popupWindow != null && popupWindow.isShowing()) {
                    popupWindow.dismiss();
                }
            }
        });
    }
    TextView textView = new TextView(getContext());
    textView.setTextColor(0xff212121);
    textView.setBackgroundResource(R.drawable.list_selector);
    if (!AndroidUtilities.isRTL()) {
        textView.setGravity(Gravity.CENTER_VERTICAL);
    } else {
        textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);
    }
    textView.setPadding(AndroidUtilities.dp(16), 0, AndroidUtilities.dp(16), 0);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    textView.setMinWidth(AndroidUtilities.dp(196));
    textView.setTag(id);
    textView.setText(text);
    if (icon != 0) {
        textView.setCompoundDrawablePadding(AndroidUtilities.dp(12));
        if (!AndroidUtilities.isRTL()) {
            textView.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(icon), null, null, null);
        } else {
            textView.setCompoundDrawablesWithIntrinsicBounds(null, null, getResources().getDrawable(icon), null);
        }
    }
    popupLayout.setShowedFromBotton(showFromBottom);
    popupLayout.addView(textView);
    LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) textView.getLayoutParams();
    if (AndroidUtilities.isRTL()) {
        layoutParams.gravity = Gravity.RIGHT;
    }
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = AndroidUtilities.dp(48);
    textView.setLayoutParams(layoutParams);
    textView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            if (popupWindow != null && popupWindow.isShowing()) {
                if (processedPopupClick) {
                    return;
                }
                processedPopupClick = true;
                popupWindow.dismiss(allowCloseAnimation);
            }
            if (parentMenu != null) {
                parentMenu.onItemClick((Integer) view.getTag());
            } else if (delegate != null) {
                delegate.onItemClick((Integer) view.getTag());
            }
        }
    });
    menuHeight += layoutParams.height;
    return textView;
}