Example usage for android.widget TextView setLayoutParams

List of usage examples for android.widget TextView setLayoutParams

Introduction

In this page you can find the example usage for android.widget TextView setLayoutParams.

Prototype

public void setLayoutParams(ViewGroup.LayoutParams params) 

Source Link

Document

Set the layout parameters associated with this view.

Usage

From source file:com.timothy.android.api.fragment.PageFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mContext = getActivity().getApplicationContext();

    //get activity and SharedPreferences
    activity = (SlidingActivity) getActivity();
    sp = activity.getSharedPreferences("AndroidAPISP", 0);
    mContext = activity.getApplicationContext();

    View mView = inflater.inflate(R.layout.view_pager_text, null);
    lineLayout = (LinearLayout) mView.findViewById(R.id.lineLayout);

    //      ContentBean bean = XMLParserUtil.getContentByIndex(mContext, getIndex());
    //      ContentBean mBean = XMLParserUtil.getContentByIndex(mContext, bean.getmIndex());

    //      String[] contentsArray = getResources().getStringArray(R.array.contents_array);
    int branchIndex = SPUtil.getIntegerFromSP(SPUtil.CURRENT_BRANCH_INDEX, sp);
    String[] contentsArray = activity.filterBranch(branchIndex);

    String contents = ContentUtil.getContentsById(contentsArray,
            SPUtil.getIntegerFromSP(SPUtil.CURRENT_INDEX, sp));
    String[] contentArray = contents.split(",");
    String contentName = contentArray[3];

    //      String superContents = ContentUtil.getSuperContentsById(contentsArray, SPUtil.getIntegerFromSP(SPUtil.CURRENT_INDEX, sp));
    //      String[] supercontentArray = superContents.split(",");
    //      String superContentName = supercontentArray[3];
    //      String name = null;
    String pageNo = null;//from w w  w . j a va2s  . c  o  m
    if (getIndex() > 0 && getPageIndex() > 0) {
        //         name = contentName;
        pageNo = String.valueOf(getPageIndex());

        String appPath = SPUtil.getFromSP(SPUtil.APP_HOME_PATH, sp);
        String branchName = SPUtil.getFromSP(SPUtil.BRANCH_PATH_NAME, sp);

        baseFolder = appPath + File.separator + branchName;
        //         String xmlurl = baseFolder +  StringUtil.rmvSpace(superContentName) + File.separator +  StringUtil.rmvSpace(contentName) + ".xml";
        String xmlurl = baseFolder + File.separator + StringUtil.rmvSpace(contentName) + ".xml";

        Log.i(LOG_TAG, "xmlurl:" + xmlurl);
        Log.i(LOG_TAG, "pageNo:" + pageNo);
        if (new File(xmlurl).exists()) {
            new GetData().execute(new String[] { xmlurl, pageNo });
        } else {
            Toast.makeText(mContext, "No Content!", Toast.LENGTH_SHORT).show();
        }
    } else {
        TextView failTV = new TextView(mContext);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.MATCH_PARENT);
        //         lp.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
        lp.gravity = Gravity.CENTER;
        lp.setMargins(2, 2, 2, 2);
        failTV.setLayoutParams(lp);
        //         failTV.setMovementMethod(ScrollingMovementMethod.getInstance()) ;
        failTV.setPadding(3, 3, 3, 3);
        int errorCode = getErrorCode();
        switch (errorCode) {
        case 1:
            failTV.setText(ERROR_MESSGE_ONE);
            break;
        case 2:
            failTV.setText(ERROR_MESSGE_TWO);
            break;
        case 3:
            failTV.setText(ERROR_MESSGE_THREE + ":" + contentArray[4]);
            break;
        case 4:
            failTV.setText(ERROR_MESSGE_FOUR + ":" + contentArray[4]);
            break;//??
        default:
            failTV.setText(ERROR_MESSGE_DEFAULT);
            break;
        }
        failTV.setTextColor(Color.RED);
        failTV.setTextSize(18.0f);
        lineLayout.addView(failTV);
    }
    //Save current page
    SPUtil.save2SP(SPUtil.SP_KEY_PAGE_INDEX, getPageIndex(), sp);
    SPUtil.save2SP(SPUtil.SP_KEY_READ_TIME, TimeUtil.getNowTimeStr(), sp);
    return mView;
}

From source file:com.example.leebeomwoo.viewbody_final.Support.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.//  ww  w .ja  v  a 2 s .  c om
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    LinearLayout.LayoutParams layout = new LinearLayout.LayoutParams(
            getResources().getDimensionPixelSize(R.dimen.subTabTileSiz_item),
            getResources().getDimensionPixelSize(R.dimen.subTabTileSiz_item));
    layout.setMargins(10, 5, 10, 5);
    textView.setLayoutParams(layout);
    return textView;
}

From source file:com.superlity.test.recyclelistviewtest.emoji.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}./*from   w  w w  .jav  a2  s.  co m*/
 */
public TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    //  display.getSize(size);
    textView.setWidth((int) (size.x / 7));
    textView.setGravity(Gravity.LEFT);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
    textView.setBackgroundResource(outValue.resourceId);
    textView.setAllCaps(true);

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}

From source file:com.tony.selene.sliding.AbSlidingSmoothTabView.java

/**
 * ??tab.//from www .  j  a  v a 2 s.  c om
 *
 * @param tabText
 *            the tab text
 * @param fragment
 *            the fragment
 */
public void addItemView(String tabText, Fragment fragment) {

    tabItemTextList.add(tabText);
    pagerItemList.add(fragment);

    tabItemList.clear();
    mTabLayout.removeAllViews();

    for (int i = 0; i < tabItemTextList.size(); i++) {
        final int index = i;
        String text = tabItemTextList.get(i);
        TextView tv = new TextView(this.context);
        tv.setTextColor(tabColor);
        tv.setTextSize(tabTextSize);
        tv.setText(text);
        tv.setGravity(Gravity.CENTER);
        tv.setLayoutParams(new LayoutParams(0, LayoutParams.FILL_PARENT, 1));
        tv.setPadding(12, 5, 12, 5);
        tv.setFocusable(false);
        tabItemList.add(tv);
        mTabLayout.addView(tv);
        tv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                mViewPager.setCurrentItem(index);
            }
        });
    }

    // ?
    AbLogUtil.d(AbSlidingSmoothTabView.class, "addItemView finish");
    mFragmentPagerAdapter.notifyDataSetChanged();
    mViewPager.setCurrentItem(0);
    computeTabImg(0);
}

From source file:com.yktx.check.widget.OldPagerSlidingTabStrip.java

private void addIconAndTextTab(final int position, int resId, String title) {
    LinearLayout layout = new LinearLayout(getContext());
    layout.setGravity(Gravity.CENTER);//from   www.j a  v a 2 s  . co m
    layout.setOrientation(LinearLayout.VERTICAL);
    ImageView tabImage = new ImageView(getContext());
    tabImage.setImageResource(resId);
    tabImage.setId(R.id.image);
    TextView tabText = new TextView(getContext());
    tabText.setText(title);
    tabText.setSingleLine();
    tabText.setId(R.id.text);
    tabText.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    tabText.setGravity(Gravity.CENTER_HORIZONTAL);
    tabText.setPadding(0, 3, 0, 0);
    layout.addView(tabImage);
    layout.addView(tabText);

    addTab(position, layout);

}

From source file:com.socialinfotech.tabbar.smart.SmartTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}./*from w ww.j  av  a2  s  . c o m*/
 */
protected TextView createDefaultTabView(CharSequence title) {
    TextView textView = new TextView(getContext());
    textView.setGravity(Gravity.CENTER);
    textView.setText(title);
    textView.setTextColor(mTabViewTextColors);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTabViewTextSize);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.MATCH_PARENT));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(mTabViewTextAllCaps);
    }

    textView.setPadding(mTabViewTextHorizontalPadding, 0, mTabViewTextHorizontalPadding, 0);

    if (mTabViewTextMinWidth > 0) {
        textView.setMinWidth(mTabViewTextMinWidth);
    }

    return textView;
}

From source file:com.chalilayang.test.customview.springindicator.SpringIndicator.java

private void addTabItems() {
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT, 1.0f);
    tabs = new ArrayList<>();
    for (int i = 0; i < viewPager.getAdapter().getCount(); i++) {
        TextView textView = new TextView(getContext());
        if (viewPager.getAdapter().getPageTitle(i) != null) {
            textView.setText(viewPager.getAdapter().getPageTitle(i));
        }//from  ww  w  . j  a  va  2  s . c o  m
        textView.setGravity(Gravity.CENTER);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
        textView.setTextColor(getResources().getColor(textColorId));
        if (textBgResId != 0) {
            textView.setBackgroundResource(textBgResId);
        }
        textView.setLayoutParams(layoutParams);
        final int position = i;
        textView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (tabClickListener == null || tabClickListener.onTabClick(position)) {
                    viewPager.setCurrentItem(position);
                }
            }
        });
        tabs.add(textView);
        tabContainer.addView(textView);
    }
}

From source file:com.timothy.android.api.fragment.PageFragment.java

public void setAllComponent(List<HtmlCleanAPI.HtmlContent> hcList) {
    Log.i(LOG_TAG, "setAllComponent()...");
    for (HtmlCleanAPI.HtmlContent hc : hcList) {
        String tag = hc.getTag();
        String content = hc.getContent();
        String contentRBlank = StringUtil.rmvEnter(StringUtil.trim(StringUtil.mergeBlank(content)));
        String contentRSpecial = StringUtil.rmvSpecial(contentRBlank);

        if (StringUtil.isEmpty(content) || StringUtil.isEmpty(contentRBlank)
                || StringUtil.isEmpty(contentRSpecial)) {
            continue;
        }/*from w w w .  jav a  2  s .c o m*/

        Log.i(LOG_TAG, "tag:" + tag);
        Log.i(LOG_TAG, "content:" + content);

        if (tag.equalsIgnoreCase("P")) {
            final TextView tagPTV = new TextView(mContext);
            tagPTV.setBackgroundResource(R.drawable.tag_p_drawable);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                    LayoutParams.WRAP_CONTENT);
            lp.setMargins(2, 2, 2, 2);
            tagPTV.setLayoutParams(lp);
            tagPTV.setPadding(3, 3, 3, 3);
            tagPTV.setPaddingRelative(3, 3, 3, 3);
            tagPTV.setMovementMethod(ScrollingMovementMethod.getInstance());
            tagPTV.setTextColor(Color.BLACK);
            tagPTV.setText(contentRSpecial);
            tagPTV.setTextSize(TEXT_SIZE);
            tagPTV.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    openDialog(tagPTV.getText().toString());
                    return false;
                }
            });
            lineLayout.addView(tagPTV);

        } else if (tag.equalsIgnoreCase("pre")) {
            final TextView tagPre = new TextView(mContext);
            tagPre.setBackgroundColor(Color.parseColor("#D2EADE"));
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                    LayoutParams.WRAP_CONTENT);
            lp.setMargins(2, 2, 2, 2);
            tagPre.setLayoutParams(lp);
            tagPre.setPadding(2, 2, 2, 2);
            tagPre.setPaddingRelative(2, 2, 2, 2);
            tagPre.setMovementMethod(ScrollingMovementMethod.getInstance());
            tagPre.setTextColor(Color.BLACK);
            //            String contentRSpecial = StringUtil.rmvSpecial(content);
            tagPre.setText(StringUtil.rmvSpecial(content));
            tagPre.setTextSize(TEXT_SIZE);
            tagPre.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    openDialog(tagPre.getText().toString());
                    return false;
                }
            });
            lineLayout.addView(tagPre);
        } else if (tag.equalsIgnoreCase("dt") || tag.equalsIgnoreCase("H1") || tag.equalsIgnoreCase("H2")
                || tag.equalsIgnoreCase("H3")) {//title
            TextView tagDtHTV = new TextView(mContext);
            tagDtHTV.setBackgroundColor(Color.DKGRAY);
            tagDtHTV.setTypeface(null, Typeface.BOLD);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                    LayoutParams.WRAP_CONTENT);
            lp.setMargins(2, 0, 2, 0);
            tagDtHTV.setLayoutParams(lp);
            tagDtHTV.setPadding(2, 2, 2, 2);
            tagDtHTV.setPaddingRelative(2, 2, 2, 2);
            tagDtHTV.setMovementMethod(ScrollingMovementMethod.getInstance());
            tagDtHTV.setTextColor(Color.WHITE);
            tagDtHTV.setText(contentRSpecial);
            tagDtHTV.setTextSize(TEXT_SIZE);
            lineLayout.addView(tagDtHTV);
        } else if (tag.equalsIgnoreCase("dd")) {
            final TextView tagDD = new TextView(mContext);
            tagDD.setBackgroundResource(R.drawable.tag_p_drawable);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                    LayoutParams.WRAP_CONTENT);
            lp.setMargins(2, 2, 2, 2);
            tagDD.setLayoutParams(lp);
            tagDD.setPadding(3, 3, 3, 3);
            tagDD.setPaddingRelative(3, 3, 3, 3);
            tagDD.setMovementMethod(ScrollingMovementMethod.getInstance());
            tagDD.setTextColor(Color.BLACK);
            tagDD.setText(contentRSpecial);
            tagDD.setTextSize(TEXT_SIZE);
            tagDD.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    openDialog(tagDD.getText().toString());
                    return false;
                }
            });
            lineLayout.addView(tagDD);
        } else if (tag.equalsIgnoreCase("li")) {
            final TextView tagLigTV = new TextView(mContext);
            tagLigTV.setBackgroundResource(R.drawable.tag_p_drawable);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                    LayoutParams.WRAP_CONTENT);
            lp.setMargins(2, 2, 2, 2);
            tagLigTV.setLayoutParams(lp);
            tagLigTV.setPaddingRelative(2, 2, 2, 2);
            tagLigTV.setMovementMethod(ScrollingMovementMethod.getInstance());
            tagLigTV.setTextColor(Color.BLACK);
            tagLigTV.setText(contentRSpecial);
            tagLigTV.setTextSize(TEXT_SIZE);
            tagLigTV.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    openDialog(tagLigTV.getText().toString());
                    return false;
                }
            });
            lineLayout.addView(tagLigTV);
        } else if (tag.equalsIgnoreCase("img")) {
            final TextView imgTV = new TextView(mContext);
            imgTV.setBackgroundResource(R.drawable.tag_p_drawable);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                    LayoutParams.WRAP_CONTENT);
            lp.setMargins(2, 2, 2, 2);
            imgTV.setLayoutParams(lp);
            imgTV.setPaddingRelative(2, 2, 2, 2);
            imgTV.setMovementMethod(ScrollingMovementMethod.getInstance());
            imgTV.setTextColor(Color.BLACK);
            imgTV.setText(content);
            imgTV.setTextSize(TEXT_SIZE);
            imgTV.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    TextView tv = (TextView) v;
                    String path = tv.getText().toString();
                    if (path != null && path.trim().length() > 0) {
                        openDialog2(path);
                    }
                }
            });
            lineLayout.addView(imgTV);
        }
    }
}

From source file:com.mycelium.wallet.activity.modern.RecordsFragment.java

private TextView createTitle(int stringResourceId) {
    TextView tv = new TextView(getActivity());
    tv.setLayoutParams(_titleLayoutParameters);
    tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
    tv.setText(stringResourceId);// w  ww.j a  v  a 2 s  . c  o  m
    tv.setGravity(Gravity.LEFT);

    tv.setTextAppearance(getActivity(), R.style.GenericText);
    // tv.setBackgroundColor(getResources().getColor(R.color.darkgrey));
    return tv;
}

From source file:edu.cmu.cylab.starslinger.view.SaveActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.Theme_Safeslinger);
    super.onCreate(savedInstanceState);

    if (savedInstanceState == null) {
        mListTopOffset = 0;/*from   ww w .  ja va2 s .c  o m*/
        mListVisiblePos = 0;
    }

    final ActionBar bar = getSupportActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    bar.setTitle(R.string.app_name);
    bar.setSubtitle(R.string.title_save);

    setContentView(R.layout.savedata);

    mListViewSaveContacts = (ListView) findViewById(R.id.SaveScrollViewMembers);
    mButtonSave = (Button) findViewById(R.id.SaveButtonSave);

    // init
    mContacts = new ArrayList<ContactStruct>();

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        byte[] data = null;
        int length = extras.size();
        mMemData = new byte[length][];
        int i = 0;
        do {
            data = extras.getByteArray(ExchangeConfig.extra.MEMBER_DATA + i);
            if (data != null) {
                mMemData[i] = data;
                i++;
            }
        } while (data != null);
    }

    // display names list so users can selectively choose which to save
    if (mMemData != null) {
        mContacts = parseVCards(mMemData);

        SaveContactAdapter adapter = new SaveContactAdapter(SaveActivity.this, mContacts);
        mListViewSaveContacts.setAdapter(adapter);

        // restore list position
        mListViewSaveContacts.setSelectionFromTop(mListVisiblePos, mListTopOffset);
    }

    mButtonSave.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            SaveSelectedContactsTask saveSelected = new SaveSelectedContactsTask();
            saveSelected.execute(new String());
        }
    });

    mListViewSaveContacts.setOnScrollListener(new OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            // nothing to do...
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            // save list position
            if (visibleItemCount != 0) {
                mListVisiblePos = firstVisibleItem;
                View v = mListViewSaveContacts.getChildAt(0);
                mListTopOffset = (v == null) ? 0 : v.getTop();
            }
        }
    });

    mUnsyncName = getString(R.string.label_None);
    mUnsyncType = getString(R.string.label_phoneOnly);

    mPrefsSelected = false;

    mTableLayoutSpin = (TableLayout) findViewById(R.id.accountLayout);
    TextView textView = new TextView(this);
    mAccountSpinner = new Spinner(this);
    textView.setText(R.string.label_SaveAccount);
    textView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    mAccountSpinner.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    mTableLayoutSpin.addView(textView);
    mTableLayoutSpin.addView(mAccountSpinner);

    // Prepare model for account spinner
    mAccounts = new ArrayList<AccountData>();
    mAccountAdapter = new AccountAdapter(this, this, mAccounts);
    mAccountSpinner.setAdapter(mAccountAdapter);

    // Load account preference if any
    mPrefAccountName = SafeSlingerPrefs.getAccountName();
    mPrefAccountType = SafeSlingerPrefs.getAccountType();

    // Prepare the system account manager. On registering the listener
    // below, we also ask for
    // an initial callback to pre-populate the account list.
    AccountManager.get(this).addOnAccountsUpdatedListener(this, null, true);

    // Register handlers for UI elements
    mAccountSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long i) {
            updateAccountSelection();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            // We don't need to worry about nothing being selected, since
            // Spinners don't allow
            // this.
        }
    });
}