android.widget.TextView#setHeight ( )源码实例Demo

下面列出了android.widget.TextView#setHeight ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

private void adjustTextViewHeight() {
    View view = getView();
    if (view == null) {
        return;
    }

    TextSwitcher textSwitcher = (TextSwitcher) view;
    TextView curr = (TextView) textSwitcher.getCurrentView();
    TextView next = (TextView) textSwitcher.getNextView();
    int currH = curr.getLineCount() * curr.getLineHeight();
    int nextH = next.getLineCount() * next.getLineHeight();
    if (currH != nextH) {
        curr.setHeight(currH);
        next.setHeight(currH);
    }
}
 
@Override
protected void onPostExecute(Void aVoid) {
    Timber.d("*** Display programs post execute");
    if (mCurrentDisplayChannelEndNdx < mAllChannels.size() - 1) {
        // Show a paging row for channels below
        int pageDnEnd = mCurrentDisplayChannelEndNdx + PAGE_SIZE;
        if (pageDnEnd >= mAllChannels.size()) pageDnEnd = mAllChannels.size() - 1;

        TextView placeHolder = new TextView(mActivity);
        placeHolder.setHeight(LiveTvGuideActivity.PAGEBUTTON_HEIGHT);
        mChannels.addView(placeHolder);

        mProgramRows.addView(new GuidePagingButton(mActivity, mFragment, mCurrentDisplayChannelEndNdx + 1, getString(R.string.lbl_load_channels) + mAllChannels.get(mCurrentDisplayChannelEndNdx + 1).getNumber() + " - " + mAllChannels.get(pageDnEnd).getNumber()));
    }

    mChannelStatus.setText(displayedChannels + " of " + mAllChannels.size() + " channels");
    mFilterStatus.setText(" for next " + mGuideHours + " hours");
    mFilterStatus.setTextColor(Color.GRAY);

    mGuideSpinner.setVisibility(View.GONE);
    if (firstRow != null) firstRow.requestFocus();
}
 
源代码3 项目: ParallaxScroll   文件: SingleParallaxListView.java
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.list_one_parallax);
	ParallaxListView listView = (ParallaxListView) findViewById(R.id.list_view);
	CustomListAdapter adapter = new CustomListAdapter(LayoutInflater.from(this));
	
	TextView v = new TextView(this);
	v.setText("PARALLAXED");
	v.setGravity(Gravity.CENTER);
	v.setTextSize(40);
	v.setHeight(200);
	v.setBackgroundResource(R.drawable.item_background);
	
	listView.addParallaxedHeaderView(v);
	listView.setAdapter(adapter);
}
 
源代码4 项目: LiteSyllabusView   文件: LiteSyllabusView.java
private void setupSectionSidebar() {
    layoutSectionSidebar = new LinearLayout(mContext);
    layoutSectionSidebar.setOrientation(VERTICAL);
    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(mSectionSidebarWidth, ViewGroup.LayoutParams.MATCH_PARENT);
    layoutSectionSidebar.setLayoutParams(params);

    for (int i = 1; i <= mSectionNumber; ++i) {
        layoutSectionSidebar.addView(getHorizontalDividerView());
        TextView tvSectionNumberTitle = new TextView(mContext);
        tvSectionNumberTitle.setWidth(mSectionSidebarWidth);
        tvSectionNumberTitle.setHeight(mSectionHeight);
        tvSectionNumberTitle.setText("" + i);
        tvSectionNumberTitle.setTextSize(SECTION_SIDEBAR_TEXT_SIZE);
        tvSectionNumberTitle.setTextColor(ContextCompat.getColor(mContext, R.color.textTitle));
        tvSectionNumberTitle.setGravity(Gravity.CENTER);
        tvSectionNumberTitle.setTypeface(mTitleTypeface);
        layoutSectionSidebar.addView(tvSectionNumberTitle);
    }

    layoutSectionSidebar.setBackgroundColor(ContextCompat.getColor(mContext, R.color.bgSectionSidbar));
}
 
源代码5 项目: UltimateAndroid   文件: SingleParallaxListView.java
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.parallax_scroll_list_one_parallax);
	ParallaxListView listView = (ParallaxListView) findViewById(R.id.list_view);
	CustomListAdapter adapter = new CustomListAdapter(LayoutInflater.from(this));
	
	TextView v = new TextView(this);
	v.setText("PARALLAXED");
	v.setGravity(Gravity.CENTER);
	v.setTextSize(40);
	v.setHeight(200);
	v.setBackgroundResource(R.drawable.parallax_scroll_item_background);
	
	listView.addParallaxedHeaderView(v);
	listView.setAdapter(adapter);
}
 
源代码6 项目: Shield   文件: LoadingBaseCell.java
@Override
public View loadingView() {
    LinearLayout rootView = (LinearLayout) getRootView();
    TextView textView = new TextView(mContext);
    textView.setHeight(ViewUtils.dip2px(getContext(), 50));
    textView.setText("loading: 加载中");
    textView.setGravity(Gravity.CENTER);
    textView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (mResetOnClickListener != null) {
                mResetOnClickListener.onClick(v);
            }
        }
    });
    rootView.addView(textView);
    return rootView;
}
 
源代码7 项目: UltimateAndroid   文件: SingleParallaxListView.java
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.parallax_scroll_list_one_parallax);
	ParallaxListView listView = (ParallaxListView) findViewById(R.id.list_view);
	CustomListAdapter adapter = new CustomListAdapter(LayoutInflater.from(this));
	
	TextView v = new TextView(this);
	v.setText("PARALLAXED");
	v.setGravity(Gravity.CENTER);
	v.setTextSize(40);
	v.setHeight(200);
	v.setBackgroundResource(R.drawable.parallax_scroll_item_background);
	
	listView.addParallaxedHeaderView(v);
	listView.setAdapter(adapter);
}
 
源代码8 项目: Shield   文件: DefaultDividerAgent.java
private View createShowView() {
    LinearLayout rootView = new LinearLayout(mContext);
    rootView.setOrientation(LinearLayout.VERTICAL);
    rootView.setLayoutParams(new ViewGroup.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
    rootView.setBackgroundColor(getContext().getResources().getColor(android.R.color.white));

    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    params.leftMargin = ViewUtils.dip2px(getContext(), 30);

    ItemViewHolder itemViewHolder = new ItemViewHolder();
    TextView textView = new TextView(mContext);
    textView.setHeight(ViewUtils.dip2px(getContext(), 50));
    textView.setGravity(Gravity.CENTER_VERTICAL);
    itemViewHolder.textView = textView;

    rootView.addView(textView, params);
    rootView.setTag(itemViewHolder);
    return rootView;
}
 
源代码9 项目: Shield   文件: LoadingBaseCell.java
@Override
public View loadingMoreView() {

    LinearLayout rootView = (LinearLayout) getRootView();

    TextView textView = new TextView(mContext);
    textView.setHeight(ViewUtils.dip2px(getContext(), 50));
    textView.setText("loadingmore: 正在载入");
    textView.setGravity(Gravity.CENTER);
    textView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mResetOnClickListener != null) {
                mResetOnClickListener.onClick(v);
            }
        }
    });
    rootView.addView(textView);
    return rootView;
}
 
源代码10 项目: Shield   文件: LoadingBaseCell.java
@Override
public View loadingMoreFailedView() {

    LinearLayout rootView = (LinearLayout) getRootView();
    TextView textView = new TextView(mContext);
    textView.setHeight(ViewUtils.dip2px(getContext(), 50));
    textView.setText("loadingmore fail: 点击重新加载");
    textView.setGravity(Gravity.CENTER);
    textView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mLoadingMoreRetryListener != null) {
                mLoadingMoreRetryListener.onClick(v);
            }
        }
    });
    rootView.addView(textView);
    return rootView;
}
 
源代码11 项目: Shield   文件: LoadingStatusAgent.java
@Override
public View onCreateView(ViewGroup parent, int viewType) {
    LinearLayout rootView = new LinearLayout(mContext);
    rootView.setOrientation(LinearLayout.VERTICAL);
    rootView.setBackgroundColor(getContext().getResources().getColor(android.R.color.white));

    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    params.leftMargin = ViewUtils.dip2px(getContext(), 30);

    itemViewHolder = new ItemViewHolder();
    TextView textView = new TextView(mContext);
    textView.setHeight(ViewUtils.dip2px(getContext(), 50));
    textView.setGravity(Gravity.CENTER_VERTICAL);
    itemViewHolder.textView = textView;

    rootView.addView(textView, params);
    rootView.setTag(itemViewHolder);
    return rootView;
}
 
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.parallax_scroll_expand_list_one_parallax);
	ParallaxExpandableListView listView = (ParallaxExpandableListView) findViewById(R.id.list_view);
	
	TextView v = new TextView(this);
	v.setText("PARALLAXED");
	v.setGravity(Gravity.CENTER);
	v.setTextSize(40);
	v.setHeight(200);
	v.setBackgroundResource(R.drawable.parallax_scroll_item_background);
	
	listView.addParallaxedHeaderView(v);
	CustomExpandableListAdapter adapter = new CustomExpandableListAdapter(LayoutInflater.from(this));
	listView.setAdapter(adapter);
}
 
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.expand_list_one_parallax);
	ParallaxExpandableListView listView = (ParallaxExpandableListView) findViewById(R.id.list_view);
	
	TextView v = new TextView(this);
	v.setText("PARALLAXED");
	v.setGravity(Gravity.CENTER);
	v.setTextSize(40);
	v.setHeight(200);
	v.setBackgroundResource(R.drawable.item_background);
	
	listView.addParallaxedHeaderView(v);
	CustomExpandableListAdapter adapter = new CustomExpandableListAdapter(LayoutInflater.from(this));
	listView.setAdapter(adapter);
}
 
源代码14 项目: xposed-rimet   文件: PluginSettingsAdapter.java
public View onCreateView(LayoutInflater layoutInflater, ViewGroup parent, int viewType) {

        CommentItemView commentItemView = new CommentItemView(getContext());
        TextView textView = commentItemView.getContentView();
        textView.setTextSize(16);
        textView.setMinLines(1);
        textView.setMaxLines(1);
        textView.setHeight(DisplayUtil.dip2px(getContext(), 32));

        return commentItemView;
    }
 
源代码15 项目: VCL-Android   文件: StringPresenter.java
public void onBindViewHolder(ViewHolder viewHolder, Object item) {
    Resources res = viewHolder.view.getContext().getResources();
    TextView tv = (TextView) viewHolder.view;
    tv.setText(item.toString());
    if (res.getString(R.string.preferences).equals(item.toString())) {
        tv.setBackground(res.getDrawable(R.drawable.ic_menu_preferences_big));
    }
    tv.setHeight(res.getDimensionPixelSize(R.dimen.grid_card_thumb_height));
    tv.setWidth(res.getDimensionPixelSize(R.dimen.grid_card_thumb_width));
}
 
源代码16 项目: tickmate   文件: TickAdapter.java
/**
 * Used to create and insert the week separator
 *
 * @param tickGrid the ViewGroup into which the week separator will be inserted
 */
private void addStartWeekSeparator(ViewGroup tickGrid) {
    TextView splitter2 = new TextView(this.context);
    splitter2.setText("");
    splitter2.setHeight(5);
    tickGrid.addView(splitter2);
    TextView splitter = new TextView(this.context);
    splitter.setText("");
    splitter.setHeight(11);
    splitter.setBackgroundResource(R.drawable.center_line);
    splitter.setPadding(0, 20, 0, 0);
    tickGrid.addView(splitter);
}
 
源代码17 项目: SmallGdufe-Android   文件: ScheduleView.java
/**
 * 横的分界线
 *
 * @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;
}
 
源代码18 项目: LiteSyllabusView   文件: LiteSyllabusView.java
private void setupWeekdayHeader() {
    layoutWeekdayHeader = new LinearLayout(mContext);
    layoutWeekdayHeader.setOrientation(HORIZONTAL);
    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, mWeekdayHeaderHeight);
    layoutWeekdayHeader.setLayoutParams(params);

    TextView tvEmptyCellOnTopAndLeft = new TextView(mContext);
    tvEmptyCellOnTopAndLeft.setWidth(mSectionSidebarWidth);
    tvEmptyCellOnTopAndLeft.setHeight(mWeekdayHeaderHeight);
    tvEmptyCellOnTopAndLeft.setText("\\");
    tvEmptyCellOnTopAndLeft.setTextSize(WEEKDAY_TITLE_TEXT_SIZE);
    tvEmptyCellOnTopAndLeft.setTextColor(ContextCompat.getColor(mContext, R.color.textTitle));
    tvEmptyCellOnTopAndLeft.setGravity(Gravity.CENTER);
    tvEmptyCellOnTopAndLeft.setTypeface(mTitleTypeface);
    layoutWeekdayHeader.addView(tvEmptyCellOnTopAndLeft);

    for (int i = 0; i < mWeekdayNumber; ++i) {
        layoutWeekdayHeader.addView(getVerticalDividerView());
        TextView tvWeekdayTitle = new TextView(mContext);
        tvWeekdayTitle.setWidth(mSectionWidth);
        tvWeekdayTitle.setHeight(mWeekdayHeaderHeight);
        tvWeekdayTitle.setText(WEEKDAY_TITLES[i]);
        tvWeekdayTitle.setTextSize(WEEKDAY_TITLE_TEXT_SIZE);
        tvWeekdayTitle.setTextColor(ContextCompat.getColor(mContext, R.color.textTitle));
        tvWeekdayTitle.setGravity(Gravity.CENTER);
        tvWeekdayTitle.setTypeface(mTitleTypeface);
        layoutWeekdayHeader.addView(tvWeekdayTitle);
    }

    layoutWeekdayHeader.setBackgroundColor(ContextCompat.getColor(mContext, R.color.bgWeekdayHeader));
}
 
源代码19 项目: Shield   文件: LoadingStatusMoreAgent.java
@Override
public View onCreateView(ViewGroup parent, int viewType) {
    LinearLayout rootView = new LinearLayout(mContext);
    rootView.setLayoutParams(new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    rootView.setOrientation(LinearLayout.VERTICAL);
    rootView.setBackgroundColor(getContext().getResources().getColor(android.R.color.white));

    if (viewType == 0) {
        View containView = LayoutInflater.from(getContext()).inflate(R.layout.agent_status_loading_more, rootView, false);
        setLoadingStatus(containView);
        rootView.addView(containView);
    } else {
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        params.setMargins(ViewUtils.dip2px(getContext(), 30), 0, 0, 0);
        itemViewHolder = new ItemViewHolder();
        TextView textView = new TextView(mContext);
        textView.setHeight(ViewUtils.dip2px(getContext(), 50));
        textView.setGravity(Gravity.CENTER_VERTICAL);
        itemViewHolder.textView = textView;
        rootView.addView(textView, params);
        rootView.setTag(itemViewHolder);
    }

    return rootView;
}
 
源代码20 项目: SmartChart   文件: PanelListAdapter.java
/**
 * 初始化横向表头的布局,必须在所有的布局都载入完之后才能调用
 * <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);
        }


    }
}
 
 方法所在类
 同类方法