本文整理汇总了Java中android.widget.LinearLayout.addView方法的典型用法代码示例。如果您正苦于以下问题:Java LinearLayout.addView方法的具体用法?Java LinearLayout.addView怎么用?Java LinearLayout.addView使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.LinearLayout
的用法示例。
在下文中一共展示了LinearLayout.addView方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initPageNumber
import android.widget.LinearLayout; //导入方法依赖的package包/类
/**
* 初始化数字页码
*/
private void initPageNumber() {
if (IndicatorManager.getInstance().getIndicatorType() == NUMBER_INDICATOR) {
mPageNumberLayout = new LinearLayout(getContext());
mPageNumberLayout.setOrientation(LinearLayout.HORIZONTAL);
mPageNumberLayout.setGravity(Gravity.CENTER);
mPageNumberLayout.removeAllViews();
mNumberViews = new NumberView[mInfos.size()];
for (int i = 0; i < mInfos.size(); i++) {
NumberView numberView;
if (i == mSelectedIndex) {
numberView = new NumberView(getContext(), NumberView.mNumberViewSelectedColor);
} else {
numberView = new NumberView(getContext(), NumberView.mNumberViewNormalColor);
}
numberView.setNumber(i + 1);
mNumberViews[i] = numberView;
mPageNumberLayout.addView(mNumberViews[i]);
}
}
}
示例2: generateDietCard
import android.widget.LinearLayout; //导入方法依赖的package包/类
private View generateDietCard(DietPlan plan) {
if (plan == null || plan.detail == null) {
return null;
}
View periodView = LayoutInflater.from(this).inflate(R.layout.ob, this.llPlan, false);
LinearLayout itemGroup = (LinearLayout) periodView.findViewById(R.id.ll_list);
TextView tvCalory = (TextView) periodView.findViewById(R.id.tv_calory);
((TextView) periodView.findViewById(R.id.tv_name)).setText(plan.name);
tvCalory.setText(Math.round(plan.calory) + "千卡");
for (int i = 0; i < plan.detail.size(); i++) {
boolean z;
DietPlanItem dietPlanItem = (DietPlanItem) plan.detail.get(i);
ViewGroup viewGroup = this.llPlan;
if (i == plan.detail.size() - 1) {
z = true;
} else {
z = false;
}
itemGroup.addView(generatePlanItem(dietPlanItem, viewGroup, z));
}
return periodView;
}
示例3: addItem
import android.widget.LinearLayout; //导入方法依赖的package包/类
private void addItem(SwipeMenuItem item, int id) {
LayoutParams params = new LayoutParams(item.getWidth(),
LayoutParams.MATCH_PARENT);
LinearLayout parent = new LinearLayout(getContext());
parent.setId(id);
parent.setGravity(Gravity.CENTER);
parent.setOrientation(LinearLayout.VERTICAL);
parent.setLayoutParams(params);
parent.setBackgroundDrawable(item.getBackground());
parent.setOnClickListener(this);
addView(parent);
if (item.getIcon() != null) {
parent.addView(createIcon(item));
}
if (!TextUtils.isEmpty(item.getTitle())) {
parent.addView(createTitle(item));
}
}
示例4: drawHourLabel
import android.widget.LinearLayout; //导入方法依赖的package包/类
private void drawHourLabel() {
LinearLayout weekViewHoursHolder = findViewById(R.id.activity_main_hours_holder);
TextView tv;
int rowHeight = mResources.getDimensionPixelOffset(R.dimen.week_view_row_height);
int minHeight = rowHeight;
int marginTop;
int marginBottom;
int marginLeftRight = mResources.getDimensionPixelSize(R.dimen.hour_text_margin_left_right);
for (int i = 1; i < 24; i++) {
if (i == 1) {
marginTop = rowHeight / 2;
} else {
marginTop = 0;
}
if (i == 23) {
marginBottom = rowHeight / 2;
} else {
marginBottom = 0;
}
String s = DateTimeHelper.getHourMinuteString(i, 0, true, false);
tv = createTextView(mContext, s, minHeight, marginTop, marginBottom, marginLeftRight);
weekViewHoursHolder.addView(tv);
}
}
示例5: pickTime
import android.widget.LinearLayout; //导入方法依赖的package包/类
/**
* 时间选择对话框
*
* @param con 上下文
* @param title 标题
* @param listener 选择事件
* @param cal 默认时间
*/
public static void pickTime(Context con, String title, Calendar cal, final OnTimeSetListener listener) {
LinearLayout ll = new LinearLayout(con);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
ll.setLayoutParams(layoutParams);
ll.setOrientation(LinearLayout.VERTICAL);
//添加一条线
LinearLayout line = new LinearLayout(con);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 1);
line.setBackgroundColor(con.getResources().getColor(R.color.line));
line.setLayoutParams(lp);
ll.addView(line);
//添加选择器控件
final TimePicker timePicker = new TimePicker(con, null, themeId);
timePicker.setLayoutParams(layoutParams);
timePicker.setCurrentHour(cal.get(Calendar.HOUR_OF_DAY));
timePicker.setCurrentMinute(cal.get(Calendar.MINUTE));
timePicker.setIs24HourView(true);
ll.addView(timePicker);
QuickDialog.Builder builder = new QuickDialog.Builder(con);
builder.setContentView(ll);
builder.setTitle(title);
builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
listener.onTimeSet(timePicker, timePicker.getCurrentHour(), timePicker.getCurrentMinute());
}
});
builder.create().show();
}
示例6: addToView
import android.widget.LinearLayout; //导入方法依赖的package包/类
private void addToView(LinearLayout linearLayout,TreeNode node){
for(int i = 0;i < node.getChildren().size();i++) {
View child = node.getChildren().get(i).getView();
if(child.getParent().getParent() != null) {
((ViewGroup)child.getParent().getParent()).removeView((View) child.getParent());
}
linearLayout.addView(((View)child.getParent()));
addToView(linearLayout,node.getChildren().get(i));
}
}
示例7: setContentView
import android.widget.LinearLayout; //导入方法依赖的package包/类
@Override
public void setContentView(View view) {
LinearLayout rootLayout = (LinearLayout) findViewById(R.id.root_layout);
if (rootLayout == null) return;
rootLayout.addView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
initToolbar();
}
示例8: onCreateContent
import android.widget.LinearLayout; //导入方法依赖的package包/类
protected void onCreateContent(LinearLayout parent) {
ContactsListView contactsList = new ContactsListView(context);
contactsList.setId(ResHelper.getIdRes(context, "clContact"));
LinearLayout.LayoutParams listParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT, 1);
contactsList.setLayoutParams(listParams);
parent.addView(contactsList);
}
示例9: onCreateView
import android.widget.LinearLayout; //导入方法依赖的package包/类
protected View onCreateView(Context context) {
mainLayout = new LinearLayout(context);
mainLayout.setBackgroundResource(ResHelper.getColorRes(context, "bbs_title_bg"));
mainLayout.setOrientation(LinearLayout.VERTICAL);
mainLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
titleBar = new TitleBar(context) {
@Override
protected View getCenterView() {
View centerview = getTitleCenterView();
if (centerview == null) {
return super.getCenterView();
}
return centerview;
}
};
LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
mainLayout.addView(titleBar, llp);
vLine = new View(context);
vLine.setBackgroundResource(ResHelper.getColorRes(context, "bbs_mainviewtitle_bg"));
mainLayout.addView(vLine, ViewGroup.LayoutParams.MATCH_PARENT, ResHelper.dipToPx(context, 1) / 2);
vLine.setVisibility(View.GONE);
View contentView = onCreateContentView(context);
// contentView.setBackgroundResource(ResHelper.getColorRes(context, "bbs_bg"));
llp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0);
llp.weight = 1;
mainLayout.addView(contentView, llp);
titleBar.setOnClickListener(newTitleBarClickListener());
return mainLayout;
}
示例10: getPlatformList
import android.widget.LinearLayout; //导入方法依赖的package包/类
private LinearLayout getPlatformList() {
LinearLayout llToolBar = new LinearLayout(getContext());
LinearLayout.LayoutParams lpTb = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
llToolBar.setLayoutParams(lpTb);
TextView tvShareTo = new TextView(getContext());
int resId = getStringRes(activity, "share_to");
if (resId > 0) {
tvShareTo.setText(resId);
}
tvShareTo.setTextColor(0xffcfcfcf);
tvShareTo.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
int dp_9 = dipToPx(getContext(), 9);
LinearLayout.LayoutParams lpShareTo = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lpShareTo.gravity = Gravity.CENTER_VERTICAL;
lpShareTo.setMargins(dp_9, 0, 0, 0);
tvShareTo.setLayoutParams(lpShareTo);
llToolBar.addView(tvShareTo);
HorizontalScrollView sv = new HorizontalScrollView(getContext());
sv.setHorizontalScrollBarEnabled(false);
sv.setHorizontalFadingEdgeEnabled(false);
LinearLayout.LayoutParams lpSv = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lpSv.setMargins(dp_9, dp_9, dp_9, dp_9);
sv.setLayoutParams(lpSv);
llToolBar.addView(sv);
llPlat = new LinearLayout(getContext());
llPlat.setLayoutParams(new HorizontalScrollView.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
sv.addView(llPlat);
return llToolBar;
}
示例11: onCreate
import android.widget.LinearLayout; //导入方法依赖的package包/类
public void onCreate() {
super.onCreate();
int screenHeight = R.getScreenHeight(activity);
float ratio = ((float) screenHeight) / DESIGN_SCREEN_WIDTH;
maxBodyHeight = 0;
llPage = new LinearLayout(activity);
llPage.setOrientation(LinearLayout.VERTICAL);
activity.setContentView(llPage);
rlTitle = new RelativeLayout(activity);
rlTitle.setBackgroundColor(0xffe6e9ec);
int titleHeight = (int) (DESIGN_TITLE_HEIGHT_L * ratio);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, titleHeight);
llPage.addView(rlTitle, lp);
initTitle(rlTitle, ratio);
RelativeLayout rlBody = new RelativeLayout(activity);
rlBody.setBackgroundColor(0xffffffff);
lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
llPage.addView(rlBody, lp);
initBody(rlBody, ratio);
LinearLayout llShadow = new LinearLayout(activity);
llShadow.setOrientation(LinearLayout.VERTICAL);
rlBody.addView(llShadow, new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
initShadow(llShadow, ratio);
llBottom = new LinearLayout(activity);
llBottom.setOrientation(LinearLayout.VERTICAL);
lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
llPage.addView(llBottom, lp);
initBottom(llBottom, ratio);
}
示例12: initBottom
import android.widget.LinearLayout; //导入方法依赖的package包/类
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);
}
示例13: onCreate
import android.widget.LinearLayout; //导入方法依赖的package包/类
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_select);
ll_select_content = (LinearLayout) findViewById(R.id.ll_select_content);
mBuyHomeViewHolder = new BuyHomeViewHolder(ll_select_content);
mBuyHomeViewHolder.init();
removeOtherView();
ll_select_content.addView(mBuyHomeViewHolder.getView());
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setItemIconTintList(null);
navigationView.setNavigationItemSelectedListener(this);
Intent intent = getIntent();
final String username = intent.getStringExtra("username");
tv0 = (TextView) navigationView.getHeaderView(0).findViewById(R.id.textView0);
tv0.setText(username);
//String path = "http://172.16.64.203:8080/数据库查询/SelectHome";
String path = RestConstants.API_HOST + "数据库查询/SelectHome";
//String path = "http://192.168.43.191:8080/数据库查询/SelectHome";
//String path = "http://172.16.88.222:8080/数据库查询/RegiStration";
Map<String, String> params = new HashMap<>();
params.put("1", "1");
OkHttpManager.getInstance().post(path, params, new OnHttpCallback() {
@Override
public void onSuccess(String str) {
String s[] = str.split("%");
String ss[] = s[0].split("#");
String sa[][] = new String[ss.length][];
for(int i=0;i<ss.length;i++){
sa[i] = ss[i].split("@");
}
//int i = 0;
List<Home> list = new ArrayList<Home>();
for (int i=0;i<sa.length;i++){
for (int j=0;j<sa[i].length;j+=17) {
System.out.println(sa[i][j]+"++++"+sa[i][j+16]);
Home home = new Home(username,sa[i][j],sa[i][j+16]);
list.add(home);
}
}
mBuyHomeViewHolder.notifySetDataChanged(list);
if("读取成功".equals(s[1])){
Toast.makeText(SelectActivity.this,s[1], Toast.LENGTH_LONG).show();
}
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
Toast.makeText(SelectActivity.this, "读取失败,请重新读取!", Toast.LENGTH_LONG).show();
}
});
}
示例14: getItemView
import android.widget.LinearLayout; //导入方法依赖的package包/类
@Override
public View getItemView(int section, int position, View convertView, ViewGroup parent) {
View x = null;
if (x == null) {
LinearLayout base = new LinearLayout(context);
base.setOrientation(LinearLayout.VERTICAL);
LinearLayout l = new LinearLayout(context);
l.setOrientation(LinearLayout.VERTICAL);
l.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
l.setPadding(50, 0, 50, 0);
typetext = new TextView(context);
typetext.setPadding(28, 0, 28, 0);
typetext.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
typetext.setTextColor(typecolor);
typetext.setTextSize(14);
timetext = new TextView(context);
timetext.setPadding(28, 0, 28, 0);
timetext.setGravity(LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT);
timetext.setTextColor(nameColor);
timetext.setTextSize(14);
setText(changes.get(position), context);
l.addView(typetext);
l.addView(timetext);
x = new CustomUserCell(context, 5, 1, false);
base.addView(x, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
base.addView(l, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
base.addView(new DividerCell(context), LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
convertView = base;
((CustomUserCell) x).setStatusColors(0xffa8a8a8, 0xff3b84c0);
convertView.setTag("Contacts");
}
TLRPC.User user = MessagesController.getInstance().getUser(changes.get(position).getUid());
((CustomUserCell) x).setData(user, null, null, 0);
convertView.setTag("Contacts");
return convertView;
}
示例15: initBody
import android.widget.LinearLayout; //导入方法依赖的package包/类
private void initBody(RelativeLayout rlBody, float ratio) {
svContent = new ScrollView(activity);
rlBody.addView(svContent, new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
LinearLayout llContent = new LinearLayout(activity);
llContent.setOrientation(LinearLayout.VERTICAL);
svContent.addView(llContent, new ScrollView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
etContent = new EditText(activity);
int padding = (int) (DESIGN_LEFT_PADDING * ratio);
etContent.setPadding(padding, padding, padding, padding);
etContent.setBackgroundDrawable(null);
etContent.setTextColor(0xff3b3b3b);
etContent.setTextSize(TypedValue.COMPLEX_UNIT_SP, 21);
etContent.setText(sp.getText());
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
llContent.addView(etContent, lp);
etContent.addTextChangedListener(this);
rlThumb = new RelativeLayout(activity);
rlThumb.setBackgroundColor(0xff313131);
int thumbWidth = (int) (DESIGN_THUMB_HEIGHT * ratio);
int xWidth = (int) (DESIGN_REMOVE_THUMB_HEIGHT * ratio);
lp = new LinearLayout.LayoutParams(thumbWidth, thumbWidth);
lp.leftMargin = lp.rightMargin = lp.bottomMargin = lp.topMargin = padding;
llContent.addView(rlThumb, lp);
aivThumb = new AsyncImageView(activity) {
public void onImageGot(String url, Bitmap bm) {
thumb = bm;
super.onImageGot(url, bm);
}
};
aivThumb.setScaleToCropCenter(true);
RelativeLayout.LayoutParams rllp = new RelativeLayout.LayoutParams(thumbWidth, thumbWidth);
rlThumb.addView(aivThumb, rllp);
aivThumb.setOnClickListener(this);
initThumb(aivThumb);
xvRemove = new XView(activity);
xvRemove.setRatio(ratio);
rllp = new RelativeLayout.LayoutParams(xWidth, xWidth);
rllp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
rllp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
rlThumb.addView(xvRemove, rllp);
xvRemove.setOnClickListener(this);
}