public void update() { LinearLayout main = (LinearLayout) (seminar.findViewById(R.id.main_layout)); if (text.equals("Loading...")) { TextView textview = new TextView(main.getContext()); textview.setText(text); textview.setTextColor(Color.WHITE); main.addView(textview); } else { if (main.getChildCount() > 0) main.removeAllViews(); JSONArray jarray; try { jarray = new JSONArray(text); for (int i = 0; i < jarray.length(); i++) { // create a new textview JSONObject json = jarray.getJSONObject(i); CustomRelativeView event = new CustomRelativeView(main.getContext(), json, i); main.addView(event); } View ruler = new View(main.getContext()); ruler.setBackgroundColor(Color.LTGRAY); main.addView(ruler, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 2)); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
public void showNumberLayout(List<ShowInfoBean> list) { LogUtil.e(getClass(), "showNumberLayout list size==>" + list.size()); showNumberLayout.removeAllViews(); LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout itemLayout = null; for (int i = 0; i < list.size(); i++) { LogUtil.e(getClass(), "showNumberLayout i==>" + i); if (i % 3 == 0) { itemLayout = (LinearLayout) LayoutInflater.from(showNumberLayout.getContext()).inflate(R.layout.show, null); itemLayout.setLayoutParams(layoutParams); showNumberLayout.addView(itemLayout); } RelativeLayout itemView = (RelativeLayout) LayoutInflater.from(showNumberLayout.getContext()).inflate(R.layout.show_item, null); initItem(itemView, list.get(i), i); LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); params.setMargins(20, 20, 0, 0); params.weight = 1; itemView.setLayoutParams(params); itemLayout.addView(itemView); } }
@Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { LinearLayout itemView = new LinearLayout(parent.getContext()); TextView textView = new TextView(parent.getContext()); textView.setTextSize(18); textView.setId(android.R.id.text1); RecyclerView.LayoutParams layoutParams = new RecyclerView.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, Converter.dp2px(itemView.getContext(), 56)); itemView.setPadding( Converter.dp2px(itemView.getContext(), 16), 0, Converter.dp2px(itemView.getContext(), 16), 0); itemView.setGravity(Gravity.LEFT | Gravity.START | Gravity.CENTER); itemView.setBackgroundResource(R.drawable.touch_feedback_holo_light); itemView.addView(textView); itemView.setLayoutParams(layoutParams); if (this.layoutManager instanceof GridLayoutManager) { calculateGridItemSize(itemView); } return new ViewHolder(itemView); }
/** 创建直选机选 */ public void createTable(LinearLayout layout) { for (int i = 0; i < balls.size(); i++) { final int index = i; int iScreenWidth = PublicMethod.getDisplayWidth(this); LinearLayout lines = new LinearLayout(layout.getContext()); for (int j = 0; j < balls.get(i).getVZhuma().size(); j++) { String color = (String) balls.get(i).getVColor().get(j); TableLayout table; if (color.equals("red")) { table = PublicMethod.makeBallTableJiXuan( null, iScreenWidth, redBallResId, balls.get(i).getBalls(j), this); } else { table = PublicMethod.makeBallTableJiXuan( null, iScreenWidth, blueBallResId, balls.get(i).getBalls(j), this); } lines.addView(table); } ImageButton delet = new ImageButton(lines.getContext()); delet.setBackgroundResource(R.drawable.shanchu); delet.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { if (balls.size() > 1) { zhumaView.removeAllViews(); balls.remove(index); isOnclik = false; jixuanZhu.setSelection(balls.size() - 1); createTable(zhumaView); } else { Toast.makeText( DanshiJiXuan.this, getResources().getText(R.string.zhixuan_jixuan_toast), Toast.LENGTH_SHORT) .show(); } } }); LinearLayout.LayoutParams param = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); param.setMargins(10, 5, 0, 0); lines.addView(delet, param); lines.setGravity(Gravity.CENTER_HORIZONTAL); if (i % 2 == 0) { lines.setBackgroundResource(R.drawable.jixuan_list_bg); } lines.setPadding(0, 3, 0, 0); layout.addView(lines); } }
private void setListViewHeight() { int itemHeight = getEstimatedToolbarHeight(mContentView.getContext()); int height = mListView.getAdapter().getCount() * itemHeight; int maxHeight = mContentView .getContext() .getResources() .getDimensionPixelSize(R.dimen.floating_toolbar_minimum_overflow_height); ViewGroup.LayoutParams params = mListView.getLayoutParams(); params.height = Math.min(height, maxHeight); mListView.setLayoutParams(params); }
public static void a(LinearLayout paramLinearLayout) { Display localDisplay = ((WindowManager) paramLinearLayout.getContext().getSystemService("window")) .getDefaultDisplay(); paramLinearLayout.setMinimumWidth(localDisplay.getWidth() - 30); paramLinearLayout.setMinimumHeight(localDisplay.getHeight() - 40); }
/** * 添加TextView * * @param linearLayout * @param ss */ public void dynamicAdd(LinearLayout linearLayout, List<String> ss) { for (String s : ss) { TextView tw = new TextView(linearLayout.getContext()); tw.setText(s); linearLayout.addView(tw); } }
private ListView createOverflowListView() { final Context context = mContentView.getContext(); final ListView overflowListView = new ListView(context); overflowListView.setLayoutParams( new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); overflowListView.setDivider(null); overflowListView.setDividerHeight(0); final ArrayAdapter overflowListViewAdapter = new ArrayAdapter<MenuItem>(context, 0) { @Override public View getView(int position, View convertView, ViewGroup parent) { TextView menuButton; if (convertView != null) { menuButton = (TextView) convertView; } else { menuButton = createOverflowMenuItemButton(context); } MenuItem menuItem = getItem(position); menuButton.setText(menuItem.getTitle()); menuButton.setContentDescription(menuItem.getTitle()); menuButton.setMinimumWidth(mOverflowWidth); return menuButton; } }; overflowListView.setAdapter(overflowListViewAdapter); return overflowListView; }
public void initUI() { LinearLayout parent = EditManager.INSTANCE.getToolsLayout(); Context context = parent.getContext(); ILayer editLayer = EditManager.INSTANCE.getEditLayer(); int padding = 2; if (editLayer != null) { createFeatureButton = new ImageButton(context); createFeatureButton.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); createFeatureButton.setBackground( Compat.getDrawable(context, R.drawable.editing_create_line)); createFeatureButton.setPadding(0, padding, 0, padding); createFeatureButton.setOnClickListener(this); createFeatureButton.setOnTouchListener(this); parent.addView(createFeatureButton); selectEditableButton = new ImageButton(context); selectEditableButton.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); selectEditableButton.setBackground( Compat.getDrawable(context, R.drawable.editing_select_editable)); selectEditableButton.setPadding(0, padding, 0, padding); selectEditableButton.setOnClickListener(this); selectEditableButton.setOnTouchListener(this); parent.addView(selectEditableButton); } selectAllButton = new ImageButton(context); selectAllButton.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); selectAllButton.setBackground(Compat.getDrawable(context, R.drawable.editing_select_all)); selectAllButton.setPadding(0, padding, 0, padding); selectAllButton.setOnClickListener(this); selectAllButton.setOnTouchListener(this); parent.addView(selectAllButton); if (editLayer != null) { undoButton = new ImageButton(context); undoButton.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); undoButton.setBackground(Compat.getDrawable(context, R.drawable.editing_undo)); undoButton.setPadding(0, padding, 0, padding); undoButton.setOnTouchListener(this); undoButton.setOnClickListener(this); parent.addView(undoButton); undoButton.setVisibility(View.GONE); commitButton = new ImageButton(context); commitButton.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); commitButton.setBackground(Compat.getDrawable(context, R.drawable.editing_commit)); commitButton.setPadding(0, padding, 0, padding); commitButton.setOnTouchListener(this); commitButton.setOnClickListener(this); parent.addView(commitButton); commitButton.setVisibility(View.GONE); } }
@SuppressLint("InflateParams") @Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreate(savedInstanceState); ll = (LinearLayout) inflater.inflate(R.layout.fragment_wordpress_list, container, false); setHasOptionsMenu(true); apiurl = this.getArguments().getString(MainActivity.DATA); constructUrls(); // Helper.admobLoader(ll.getContext(), getResources(), ll.findViewById(R.id.adView)); View footerView = inflater.inflate(R.layout.listview_footer, null); RelativeLayout dialogLayout = (RelativeLayout) ll.findViewById(R.id.progressBarHolder); feedListView = (ListView) ll.findViewById(R.id.custom_list); mInfo = new WordpressGetTaskInfo( footerView, feedListView, ll.getContext(), dialogLayout, ll, apiurl, false); feedListView.setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> a, View v, int position, long id) { Object o = feedListView.getItemAtPosition(position); PostItem newsData = (PostItem) o; Intent intent = new Intent(mAct, WordpressDetailActivity.class); intent.putExtra("feed", newsData); intent.putExtra("apiurl", apiurl); startActivity(intent); } }); feedListView.setOnScrollListener( new OnScrollListener() { @Override public void onScroll( AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (mInfo.feedListAdapter == null) return; if (mInfo.feedListAdapter.getCount() == 0) return; int l = visibleItemCount + firstVisibleItem; if (l >= totalItemCount && !mInfo.isLoading && mInfo.curpage <= mInfo.pages) { mTask = new WordpressGetTask(baseurl, false, mInfo); mTask.execute(); } } @Override public void onScrollStateChanged(AbsListView view, int scrollState) {} }); return ll; }
public void onClick(View v) { if (v == selectAllButton) { Tool currentTool = EditManager.INSTANCE.getActiveTool(); if (currentTool != null && currentTool instanceof InfoTool) { // if the same tool is re-selected, it is disabled EditManager.INSTANCE.setActiveTool(null); } else { // check maps enablement try { final Collection<SpatialVectorTable> spatialTables = SpatialiteSourcesManager.INSTANCE.getSpatialiteMaps2TablesMap().values(); boolean atLeastOneEnabled = false; for (SpatialVectorTable spatialVectorTable : spatialTables) { if (spatialVectorTable.getStyle().enabled == 1) { atLeastOneEnabled = true; break; } } if (!atLeastOneEnabled) { LinearLayout parent = EditManager.INSTANCE.getToolsLayout(); if (parent != null) { Context context = parent.getContext(); GPDialogs.warningDialog( context, context.getString(R.string.no_queriable_layer_is_visible), null); } return; } } catch (Exception e) { GPLog.error(this, null, e); } Tool activeTool = new InfoTool(this, mapView); EditManager.INSTANCE.setActiveTool(activeTool); } } else if (v == selectEditableButton) { Tool currentTool = EditManager.INSTANCE.getActiveTool(); if (currentTool != null && currentTool instanceof SelectionTool) { // if the same tool is re-selected, it is disabled EditManager.INSTANCE.setActiveTool(null); } else { Tool activeTool = new SelectionTool(mapView); EditManager.INSTANCE.setActiveTool(activeTool); } } else if (v == createFeatureButton) { ToolGroup createFeatureToolGroup = new LineCreateFeatureToolGroup(mapView, null); EditManager.INSTANCE.setActiveToolGroup(createFeatureToolGroup); } else if (v == undoButton) { // if (cutExtendProcessedFeature != null) { // EditManager.INSTANCE.setActiveTool(null); // commitButton.setVisibility(View.GONE); // undoButton.setVisibility(View.GONE); // EditManager.INSTANCE.invalidateEditingView(); // } } handleToolIcons(v); }
private View getView(final Tag tag) { final View convertView = LayoutInflater.from(linearLayout.getContext()) .inflate(R.layout.poi_tag_list_item, null, false); final EditText tagEditText = (EditText) convertView.findViewById(R.id.tagEditText); tagEditText.setText(tag.tag); final EditText valueEditText = (EditText) convertView.findViewById(R.id.valueEditText); ImageButton deleteItemImageButton = (ImageButton) convertView.findViewById(R.id.deleteItemImageButton); valueEditText.setText(tag.value); deleteItemImageButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { linearLayout.removeView((View) v.getParent()); editPoiData.tags.remove(tag); if (mIsUserInput) editPoiData.notifyDatasetChanged(mTagsChangedListener); } }); tagEditText.addTextChangedListener( new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void onTextChanged(CharSequence s, int start, int before, int count) {} @Override public void afterTextChanged(Editable s) { editPoiData.tags.remove(tag); tag.tag = tagEditText.getText().toString(); editPoiData.tags.add(tag); if (mIsUserInput) editPoiData.notifyDatasetChanged(mTagsChangedListener); } }); valueEditText.addTextChangedListener( new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void onTextChanged(CharSequence s, int start, int before, int count) {} @Override public void afterTextChanged(Editable s) { editPoiData.tags.remove(tag); tag.value = valueEditText.getText().toString(); editPoiData.tags.add(tag); if (mIsUserInput) editPoiData.notifyDatasetChanged(mTagsChangedListener); } }); return convertView; }
private void displayOrHideContactPicture( LinearLayout callView, Uri pictureUri, Uri thumbnailUri, boolean hide) { AvatarWithShadow contactPicture = (AvatarWithShadow) callView.findViewById(R.id.contactPicture); if (pictureUri != null) { LinphoneUtils.setImagePictureFromUri( callView.getContext(), contactPicture.getView(), Uri.parse(pictureUri.toString()), thumbnailUri, R.drawable.unknown_small); } callView.setVisibility(hide ? View.GONE : View.VISIBLE); }
private void displayCall(Resources resources, LinphoneCall call, int index) { String sipUri = call.getRemoteAddress().asStringUriOnly(); LinphoneAddress lAddress; try { lAddress = LinphoneCoreFactory.instance().createLinphoneAddress(sipUri); } catch (LinphoneCoreException e) { Log.e("Incall activity cannot parse remote address", e); lAddress = LinphoneCoreFactory.instance().createLinphoneAddress("uknown", "unknown", "unkonown"); } // Control Row LinearLayout callView = (LinearLayout) inflater.inflate(R.layout.active_call_control_row, container, false); callView.setId(index + 1); setContactName(callView, lAddress, sipUri, resources); displayCallStatusIconAndReturnCallPaused(callView, call); setRowBackground(callView, index); registerCallDurationTimer(callView, call); callsList.addView(callView); // Image Row LinearLayout imageView = (LinearLayout) inflater.inflate(R.layout.active_call_image_row, container, false); Contact contact = ContactsManager.getInstance() .findContactWithAddress(imageView.getContext().getContentResolver(), lAddress); if (contact != null) { displayOrHideContactPicture( imageView, contact.getPhotoUri(), contact.getThumbnailUri(), false); } else { displayOrHideContactPicture(imageView, null, null, false); } callsList.addView(imageView); callView.setTag(imageView); callView.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { if (v.getTag() != null) { View imageView = (View) v.getTag(); if (imageView.getVisibility() == View.VISIBLE) imageView.setVisibility(View.GONE); else imageView.setVisibility(View.VISIBLE); callsList.invalidate(); } } }); }
private void selectCurrentPack(int position) { for (int i = 0; i < stickerIndicatorContainer.getChildCount(); i++) { if (stickerIndicatorContainer.getChildAt(i) != null) { stickerIndicatorContainer.getChildAt(i).setBackgroundColor(Color.TRANSPARENT); } } if (stickerIndicatorContainer.getChildAt(position) != null) { stickerIndicatorContainer .getChildAt(position) .setBackgroundColor( stickerIndicatorContainer .getContext() .getResources() .getColor(R.color.selector_selected)); } }
private void setContactName( LinearLayout callView, LinphoneAddress lAddress, String sipUri, Resources resources) { TextView contact = (TextView) callView.findViewById(R.id.contactNameOrNumber); Contact lContact = ContactsManager.getInstance() .findContactWithAddress(callView.getContext().getContentResolver(), lAddress); if (lContact == null) { if (resources.getBoolean(R.bool.only_display_username_if_unknown) && LinphoneUtils.isSipAddress(sipUri)) { contact.setText(lAddress.getUserName()); } else { contact.setText(sipUri); } } else { contact.setText(lContact.getName()); } }
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); recViewLogin = (LinearLayout) getView().findViewById(R.id.login_layout); // Restore from saved instance state // [START restore_saved_instance_state] if (savedInstanceState != null) { mIsResolving = savedInstanceState.getBoolean(KEY_IS_RESOLVING); mShouldResolve = savedInstanceState.getBoolean(KEY_SHOULD_RESOLVE); } // [END restore_saved_instance_state] // Set up button click listeners recViewLogin.findViewById(R.id.sign_in_button).setOnClickListener(this); recViewLogin.findViewById(R.id.sign_out_button).setOnClickListener(this); recViewLogin.findViewById(R.id.disconnect_button).setOnClickListener(this); // Large sign-in ((SignInButton) recViewLogin.findViewById(R.id.sign_in_button)).setSize(SignInButton.SIZE_WIDE); // Start with sign-in button disabled until sign-in either succeeds or fails recViewLogin.findViewById(R.id.sign_in_button).setEnabled(false); // Set up view instances mStatus = (TextView) recViewLogin.findViewById(R.id.status); // [START create_google_api_client] // Build GoogleApiClient with access to basic profile mGoogleApiClient = new GoogleApiClient.Builder(recViewLogin.getContext()) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(Plus.API) .addScope(new Scope(Scopes.PROFILE)) .addScope(new Scope(Scopes.EMAIL)) .build(); // [END create_google_api_client] mActivity = getActivity(); }
@Override public View getView(final int position, View convertView, ViewGroup parent) { switch (getItemViewType(position)) { case 0: if (convertView == null) { convertView = inflater.inflate(R.layout.index_nav_item_toptable, null, false); } TableView tableView = (TableView) convertView.findViewById(R.id.table); tableView.setContents(item.getTopTable().getContents(), item.getTopTable().getUrls()); tableView.setOnContentClickListener(onContentClickListener); break; case 1: if (convertView == null) { convertView = inflater.inflate(R.layout.index_nav_item_ads, null, false); } final FitWidthImageView adsImage = (FitWidthImageView) convertView.findViewById(R.id.image); new AsyncTask<Void, Void, Bitmap>() { @Override protected Bitmap doInBackground(Void... params) { Bitmap bitmap = null; File image = new File( Environment.getExternalStorageDirectory(), Constants.SDCARD_HTML_FOLDER + "/" + item.getAdsImageUrl()); if (image.exists()) { try { bitmap = BitmapFactory.decodeFile(image.getPath()); } catch (Exception e) { e.printStackTrace(); } } return bitmap; } @Override protected void onPostExecute(Bitmap result) { if (result != null) { adsImage.setImageBitmap(result); adsImage.setClickable(true); adsImage.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { if (onContentClickListener != null) { onContentClickListener.onContentClick(item.getAdsUrl()); } } }); } } }.execute(); break; case 2: if (convertView == null) { convertView = inflater.inflate(R.layout.index_nav_item_bottomlist, null, false); } if (position == 2) { convertView.setBackgroundResource(R.drawable.bottomlist_bg_head); } else if (position == getCount() - 1) { convertView.setBackgroundResource(R.drawable.bottomlist_bg_foot); } else { convertView.setBackgroundResource(R.drawable.bottomlist_bg_middle); } final ImageView icon = (ImageView) convertView.findViewById(R.id.icon); new AsyncTask<Void, Void, Bitmap>() { @Override protected Bitmap doInBackground(Void... params) { Bitmap bitmap = null; File image = new File( Environment.getExternalStorageDirectory(), Constants.SDCARD_HTML_FOLDER + "/" + item.getBottomList().get(position - 2).getIconPath()); if (image.exists()) { try { bitmap = BitmapFactory.decodeFile(image.getPath()); } catch (Exception e) { e.printStackTrace(); } } return bitmap; } @Override protected void onPostExecute(Bitmap result) { if (result != null) { icon.setImageBitmap(result); } } }.execute(); ((TextView) convertView.findViewById(R.id.title)) .setText(item.getBottomList().get(position - 2).getTitle()); ((TextView) convertView.findViewById(R.id.subtitle)) .setText(item.getBottomList().get(position - 2).getSubTitle()); final LinearLayout tableContainer = (LinearLayout) convertView.findViewById(R.id.table_container); if (tableContainer.getChildCount() > 0) { tableContainer.removeAllViews(); } final Table[] tables = item.getBottomList().get(position - 2).getTables(); for (int i = 0; i < tables.length; i++) { if (tables[i].getTitle() != null && tables[i].getTitle().length() > 0) { View setionTitle = inflater.inflate(R.layout.index_nav_item_bottomlist_item_title, null, false); ((TextView) setionTitle.findViewById(R.id.setion_title)).setText(tables[i].getTitle()); final int ii = i; setionTitle.setClickable(true); setionTitle.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { if (onContentClickListener != null && tables[ii].getTitleUrl() != null) { onContentClickListener.onContentClick(tables[ii].getTitleUrl()); } } }); tableContainer.addView(setionTitle); } TableView tableViewItem = new TableView(tableContainer.getContext()); tableViewItem.setContents(tables[i].getContents(), tables[i].getUrls()); tableViewItem.setOnContentClickListener(onContentClickListener); tableContainer.addView(tableViewItem); } final View divider = convertView.findViewById(R.id.divider); convertView .findViewById(R.id.title_layout) .setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { if (tableContainer.getVisibility() == View.GONE) { tableContainer.setVisibility(View.VISIBLE); if (position == getCount() - 1) { divider.setVisibility(View.VISIBLE); } } else { tableContainer.setVisibility(View.GONE); if (position == getCount() - 1) { divider.setVisibility(View.GONE); } } } }); break; } return convertView; }
/** * Constructor. * * @param mapView the map view. */ public LineMainEditingToolGroup(MapView mapView) { this.mapView = mapView; LinearLayout parent = EditManager.INSTANCE.getToolsLayout(); selectionColor = Compat.getColor(parent.getContext(), R.color.main_selection); }
public void notifyDataSetChanged() { super.removeAllViews(); layout.removeAllViews(); if (!scrollable) { // not scrollable tabs int tabWidth = this.getWidth() / tabs.size(); // set params for resizing tabs width LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(tabWidth, HorizontalScrollView.LayoutParams.MATCH_PARENT); for (MaterialTab t : tabs) { layout.addView(t.getView(), params); } } else { // scrollable tabs if (!isTablet) { for (int i = 0; i < tabs.size(); i++) { LinearLayout.LayoutParams params; MaterialTab tab = tabs.get(i); int tabWidth = (int) (tab.getTabMinWidth() + (24 * density)); // 12dp // + // text/icon // width // + // 12dp if (i == 0) { // first tab View view = new View(layout.getContext()); view.setMinimumWidth((int) (60 * density)); layout.addView(view); } params = new LinearLayout.LayoutParams( tabWidth, HorizontalScrollView.LayoutParams.MATCH_PARENT); layout.addView(tab.getView(), params); if (i == tabs.size() - 1) { // last tab View view = new View(layout.getContext()); view.setMinimumWidth((int) (60 * density)); layout.addView(view); } } } else { // is a tablet for (int i = 0; i < tabs.size(); i++) { LinearLayout.LayoutParams params; MaterialTab tab = tabs.get(i); int tabWidth = (int) (tab.getTabMinWidth() + (48 * density)); // 24dp // + // text/icon // width // + // 24dp params = new LinearLayout.LayoutParams( tabWidth, HorizontalScrollView.LayoutParams.MATCH_PARENT); layout.addView(tab.getView(), params); } } } if (isTablet && scrollable) { // if device is a tablet and have scrollable tabs add right and left // arrows Resources res = getResources(); left = new ImageButton(this.getContext()); left.setId(R.id.left); left.setImageDrawable(res.getDrawable(R.drawable.left_arrow)); left.setBackgroundColor(Color.TRANSPARENT); left.setOnClickListener(this); // set 56 dp width and 48 dp height RelativeLayout.LayoutParams paramsLeft = new LayoutParams((int) (56 * density), (int) (48 * density)); paramsLeft.addRule(RelativeLayout.ALIGN_PARENT_LEFT); paramsLeft.addRule(RelativeLayout.ALIGN_PARENT_TOP); paramsLeft.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); this.addView(left, paramsLeft); right = new ImageButton(this.getContext()); right.setId(R.id.right); right.setImageDrawable(res.getDrawable(R.drawable.right_arrow)); right.setBackgroundColor(Color.TRANSPARENT); right.setOnClickListener(this); RelativeLayout.LayoutParams paramsRight = new LayoutParams((int) (56 * density), (int) (48 * density)); paramsRight.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); paramsRight.addRule(RelativeLayout.ALIGN_PARENT_TOP); paramsRight.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); this.addView(right, paramsRight); RelativeLayout.LayoutParams paramsScroll = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); paramsScroll.addRule(RelativeLayout.LEFT_OF, R.id.right); paramsScroll.addRule(RelativeLayout.RIGHT_OF, R.id.left); this.addView(scrollView, paramsScroll); } else { // if is not a tablet add only scrollable content RelativeLayout.LayoutParams paramsScroll = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); this.addView(scrollView, paramsScroll); } this.setSelectedNavigationItem(tabSelected); }
@Override public void attach(LinearLayout baseLayout) { baseLayout.addView(getLayout(baseLayout.getContext())); }
/** * 创建BallTable * * @param LinearLayout aParentView 上一级Layout * @param int aLayoutId 当前BallTable的LayoutId * @param int aFieldWidth BallTable区域的宽度(如屏幕宽度) * @param int aBallNum 小球个数 * @param int aBallViewWidth 小球视图的宽度(图片宽度) * @param int[] aResId 小球图片Id * @param int aIdStart 小球Id起始数值 * @param int aBallViewText 0:小球从0开始显示,1:小球从1开始显示 ,3小球从3开始显示(福彩3D和值组6从3开始) * @return BallTable */ private BallTable makeBallTable( LinearLayout aParentView, int aLayoutId, int aFieldWidth, int aBallNum, int[] aResId, int aIdStart, int aBallViewText) { BallTable iBallTable = new BallTable(aParentView, aLayoutId, aIdStart); int iBallNum = aBallNum; int iFieldWidth = aFieldWidth; int scrollBarWidth = 6; // 定义没行小球的个数为7 int viewNumPerLine = 7; int iBallViewWidth = (iFieldWidth - scrollBarWidth) / viewNumPerLine - 2; int lineNum = iBallNum / viewNumPerLine; int lastLineViewNum = iBallNum % viewNumPerLine; int margin = (iFieldWidth - scrollBarWidth - (iBallViewWidth + 2) * viewNumPerLine) / 2; int iBallViewNo = 0; for (int row = 0; row < lineNum; row++) { TableRow tableRow = new TableRow(aParentView.getContext()); for (int col = 0; col < viewNumPerLine; col++) { String iStrTemp = ""; if (aBallViewText == 0) { iStrTemp = "" + (iBallViewNo); // 小球从0开始 } else if (aBallViewText == 1) { iStrTemp = "" + (iBallViewNo + 1); // 小球从1开始 } else if (aBallViewText == 3) { iStrTemp = "" + (iBallViewNo + 3); // 小球从3开始 } OneBallView tempBallView = new OneBallView(aParentView.getContext()); tempBallView.setId(aIdStart + iBallViewNo); tempBallView.initBall(iBallViewWidth, iBallViewWidth, iStrTemp, aResId); tempBallView.setOnClickListener(this); iBallTable.addBallView(tempBallView); TableRow.LayoutParams lp = new TableRow.LayoutParams(); if (col == 0) { lp.setMargins(margin + 1, 1, 1, 1); } else if (col == viewNumPerLine - 1) { lp.setMargins(1, 1, margin + scrollBarWidth + 1, 1); } else lp.setMargins(1, 1, 1, 1); tableRow.addView(tempBallView, lp); iBallViewNo++; } // 新建的TableRow添加到TableLayout iBallTable.tableLayout.addView(tableRow, new TableLayout.LayoutParams(FP, WC)); } if (lastLineViewNum > 0) { TableRow tableRow = new TableRow(this); for (int col = 0; col < lastLineViewNum; col++) { String iStrTemp = ""; if (aBallViewText == 0) { iStrTemp = "" + (iBallViewNo); // 小球从0开始 } else if (aBallViewText == 1) { iStrTemp = "" + (iBallViewNo + 1); // 小球从1开始 } else if (aBallViewText == 3) { iStrTemp = "" + (iBallViewNo + 3); // 小球从3开始 } OneBallView tempBallView = new OneBallView(aParentView.getContext()); tempBallView.setId(aIdStart + iBallViewNo); tempBallView.initBall(iBallViewWidth, iBallViewWidth, iStrTemp, aResId); tempBallView.setOnClickListener(this); iBallTable.addBallView(tempBallView); TableRow.LayoutParams lp = new TableRow.LayoutParams(); if (col == 0) { lp.setMargins(margin + 1, 1, 1, 1); } else lp.setMargins(1, 1, 1, 1); tableRow.addView(tempBallView, lp); iBallViewNo++; } // 新建的TableRow添加到TableLayout iBallTable.tableLayout.addView(tableRow, new TableLayout.LayoutParams(FP, WC)); } return iBallTable; }