List of usage examples for android.widget LinearLayout addView
public void addView(View child, int index)
From source file:Main.java
public static View addSpacer(LinearLayout row) { View spacer = new View(row.getContext()); // if (DEBUG) spacer.setBackgroundColor(Color.GREEN); android.widget.LinearLayout.LayoutParams params = new android.widget.LinearLayout.LayoutParams( DEBUG ? 1 : 0, DEBUG ? 1 : 0, 1); row.addView(spacer, params); return spacer; }
From source file:com.nagopy.android.xposed.utilities.ModBrightness.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) @XMinSdkVersion(Build.VERSION_CODES.JELLY_BEAN_MR1) @HandleInitPackageResources(targetPackage = XConst.PKG_SYSTEM_UI, summary = "??") public static void brightnessDebugger(final String modulePath, final InitPackageResourcesParam resparam, final ModBrightnessSettingsGen settings) throws Throwable { if (!settings.brightnessDebugger) { return;/* ww w .j av a 2 s . com*/ } resparam.res.hookLayout(XConst.PKG_SYSTEM_UI, "layout", "super_status_bar", new XC_LayoutInflated() { @Override public void handleLayoutInflated(LayoutInflatedParam liparam) throws Throwable { LinearLayout parent = (LinearLayout) liparam.view .findViewById(liparam.res.getIdentifier("system_icon_area", "id", XConst.PKG_SYSTEM_UI)); // ? TextView luxTextView = new TextView(parent.getContext()); luxTextView.setTextSize(8); luxTextView.setSingleLine(false); luxTextView.setTextColor(Color.WHITE); luxTextView.setText(""); parent.setGravity(Gravity.CENTER_VERTICAL); parent.addView(luxTextView, 0); AutoBrightnessController autoBrightnessChangedReceiver = new AutoBrightnessController(luxTextView); IntentFilter intentFilter = new IntentFilter( AutoBrightnessController.ACTION_AUTO_BRIGHTNESS_CHANGED); intentFilter.addAction(Intent.ACTION_SCREEN_OFF); parent.getContext().registerReceiver(autoBrightnessChangedReceiver, intentFilter); } }); }
From source file:com.google.unity.AdMobPlugin.java
/** * Creates an {@link AdView} to old ads. * * @param activity The activity to place the {@code AdView}. * @param publisherId Your publisher ID from the AdMob or DFP console * @param adSizeString A string ad size constant representing the desired ad size. * @param positionAtTop True to position the ad at the top of the screen. False to position * the ad at the bottom of the screen. *///from www . j ava 2 s .co m public static void createBannerView(final Activity activity, final String publisherId, final String adSizeString, final boolean positionAtTop) { Log.d(LOGTAG, "called createBannerView in Java code"); final AdMobPlugin plugin = AdMobPlugin.instance(); plugin.activity = activity; activity.runOnUiThread(new Runnable() { @Override public void run() { AdSize adSize = AdMobPlugin.adSizeFromSize(adSizeString); if (adSize == null) { Log.e(AdMobPlugin.LOGTAG, "AdSize is null. Did you use an AdSize constant?"); return; } plugin.adView = new AdView(activity, adSize, publisherId); plugin.adView.setAdListener(plugin); LinearLayout layout = new LinearLayout(activity); FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams( FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT); layoutParams.gravity = positionAtTop ? Gravity.TOP : Gravity.BOTTOM; activity.addContentView(layout, layoutParams); LinearLayout.LayoutParams adParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT); layout.addView(plugin.adView, adParams); } }); }
From source file:com.example.machine2.MyDynamicWorkoutChartFragment.java
public void drawChart() { Log.i("MyDynamicWorkoutChar", "..... Start of drawChart ....."); newView = line.getView(getActivity()); LinearLayout layout = (LinearLayout) getActivity().findViewById(R.id.my_workout_chart_layout); layout.addView(newView, new LayoutParams(LayoutParams.MATCH_PARENT)); Log.i("MyDynamicWorkoutChar", "..... End of drawChart ....."); }
From source file:com.androidhiddencamera.HiddenCameraFragment.java
/** * Add camera preview to the root of the activity layout. * * @return {@link CameraPreview} that was added to the view. *///from w w w .jav a 2 s.c o m private CameraPreview addPreView() { //create fake camera view CameraPreview cameraSourceCameraPreview = new CameraPreview(getActivity(), this); cameraSourceCameraPreview.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); View view = ((ViewGroup) getActivity().getWindow().getDecorView().getRootView()).getChildAt(0); if (view instanceof LinearLayout) { LinearLayout linearLayout = (LinearLayout) view; LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(1, 1); linearLayout.addView(cameraSourceCameraPreview, params); } else if (view instanceof RelativeLayout) { RelativeLayout relativeLayout = (RelativeLayout) view; RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(1, 1); params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE); relativeLayout.addView(cameraSourceCameraPreview, params); } else if (view instanceof FrameLayout) { FrameLayout frameLayout = (FrameLayout) view; FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(1, 1); frameLayout.addView(cameraSourceCameraPreview, params); } else { throw new RuntimeException("Root view of the activity/fragment cannot be frame layout"); } return cameraSourceCameraPreview; }
From source file:com.androidhiddencamera.HiddenCameraActivity.java
/** * Add camera preview to the root of the activity layout. * * @return {@link CameraPreview} that was added to the view. *///w w w .ja va 2 s . co m private CameraPreview addPreView() { //create fake camera view CameraPreview cameraSourceCameraPreview = new CameraPreview(this, this); cameraSourceCameraPreview.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); View view = ((ViewGroup) getWindow().getDecorView().getRootView()).getChildAt(0); if (view instanceof LinearLayout) { LinearLayout linearLayout = (LinearLayout) view; LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(1, 1); linearLayout.addView(cameraSourceCameraPreview, params); } else if (view instanceof RelativeLayout) { RelativeLayout relativeLayout = (RelativeLayout) view; RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(1, 1); params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE); relativeLayout.addView(cameraSourceCameraPreview, params); } else if (view instanceof FrameLayout) { FrameLayout frameLayout = (FrameLayout) view; FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(1, 1); frameLayout.addView(cameraSourceCameraPreview, params); } else { throw new RuntimeException("Root view of the activity/fragment cannot be frame layout"); } return cameraSourceCameraPreview; }
From source file:com.github.capone.controller.favorites.FavoritesFragment.java
@Override public void onClick(View v) { LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); final EditText name = new EditText(getActivity()); name.setHint(R.string.server_name);/*w w w . j a v a 2 s. co m*/ final EditText address = new EditText(getActivity()); address.setHint(R.string.server_address); final EditText publicKey = new EditText(getActivity()); publicKey.setHint(R.string.public_key); LinearLayout layout = new LinearLayout(getActivity()); layout.setOrientation(LinearLayout.VERTICAL); layout.addView(name, params); layout.addView(address, params); layout.addView(publicKey, params); new AlertDialog.Builder(getActivity()).setTitle(R.string.title_add_favorite) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { addServer(name.getText().toString(), address.getText().toString(), publicKey.getText().toString()); } }).setView(layout).show(); }
From source file:bg.phpgcm2.MainActivity.java
private void newButton(String str, int num) { LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); params.height = 30;/*from w ww .j a v a 2 s .c o m*/ final LinearLayout lm = (LinearLayout) findViewById(R.id.mainLayout); Button btn = new Button(this); btn.setId(num); get_map_data_btn_id = btn.getId(); btn.setText("get_map_data"); btn.setBackgroundColor(Color.rgb(170, 180, 190)); lm.addView(btn, params); Button btn1 = ((Button) findViewById(get_map_data_btn_id)); btn1.setPadding(0, 0, 0, 0); btn1.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { SharedPreferences settings = getSharedPreferences("Motolife", MODE_PRIVATE); String fb = settings.getString("fb", "0"); Toast.makeText(view.getContext(), "Button clicked index = " + get_map_data_btn_id, Toast.LENGTH_SHORT).show(); } }); }
From source file:au.com.cybersearch2.classyfy.TitleSearchResultsActivityTest.java
@Test public void test_dynamic_layout() throws Exception { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSSSS", new Locale("en", "AU")); RecordCategory recordCategory = new RecordCategory(); Date created = sdf.parse("2014-02-05 18:45:46.145000"); Date modified = sdf.parse("2014-02-12 11:55:23.121000"); recordCategory.setCreated(created);//w w w . j a v a 2 s.co m recordCategory.setModified(modified); recordCategory.setCreator("admin"); recordCategory.setDescription("Information Technology"); recordCategory.setIdentifier("2014-1391586274589"); FieldDescriptor descriptionField = new FieldDescriptor(); descriptionField.setOrder(1); descriptionField.setName("description"); descriptionField.setTitle("Description"); FieldDescriptor createdField = new FieldDescriptor(); createdField.setOrder(2); createdField.setName("created"); createdField.setTitle("Created"); FieldDescriptor creatorField = new FieldDescriptor(); creatorField.setOrder(3); creatorField.setName("creator"); creatorField.setTitle("Creator"); FieldDescriptor modifiedField = new FieldDescriptor(); modifiedField.setOrder(4); modifiedField.setName("modified"); modifiedField.setTitle("Modified"); FieldDescriptor modifier = new FieldDescriptor(); modifier.setOrder(5); modifier.setName("modifier"); modifier.setTitle("Modifier"); FieldDescriptor identifierField = new FieldDescriptor(); identifierField.setOrder(6); identifierField.setName("identifier"); identifierField.setTitle("Identifier"); Set<FieldDescriptor> fieldSet = new TreeSet<FieldDescriptor>(); fieldSet.add(descriptionField); fieldSet.add(createdField); fieldSet.add(creatorField); fieldSet.add(modifiedField); fieldSet.add(modifier); fieldSet.add(identifierField); @SuppressWarnings("unchecked") Map<String, Object> valueMap = PropertyUtils.describe(recordCategory); titleSearchResultsActivity = (TitleSearchResultsActivity) controller.create().get(); LinearLayout dynamicLayout = new LinearLayout(titleSearchResultsActivity); dynamicLayout.setOrientation(LinearLayout.VERTICAL); int layoutHeight = LinearLayout.LayoutParams.MATCH_PARENT; int layoutWidth = LinearLayout.LayoutParams.WRAP_CONTENT; for (FieldDescriptor descriptor : fieldSet) { Object value = valueMap.get(descriptor.getName()); if (value == null) continue; TextView titleView = new TextView(titleSearchResultsActivity); titleView.setText(descriptor.getTitle()); TextView valueView = new TextView(titleSearchResultsActivity); valueView.setText(value.toString()); LinearLayout fieldLayout = new LinearLayout(titleSearchResultsActivity); fieldLayout.setOrientation(LinearLayout.HORIZONTAL); fieldLayout.addView(titleView, new LinearLayout.LayoutParams(layoutWidth, layoutHeight)); fieldLayout.addView(valueView, new LinearLayout.LayoutParams(layoutWidth, layoutHeight)); } }
From source file:com.kaedea.frontia.demo.DemoListFragment.java
@SuppressWarnings("ResourceType") public static View getItemViewLayout(Context context) { LinearLayout linearLayout = new LinearLayout(context); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.setGravity(Gravity.CENTER_VERTICAL); int[] attrs = new int[] { R.attr.selectableItemBackground }; TypedArray typedArray = context.obtainStyledAttributes(attrs); int backgroundResource = typedArray.getResourceId(0, 0); linearLayout.setBackgroundResource(backgroundResource); typedArray.recycle();// w w w . j ava2 s . co m LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); linearLayout.setLayoutParams(layoutParams); // Title TextView tvTitle = new TextView(context); tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16f); tvTitle.setMaxLines(1); tvTitle.setTextColor(Color.parseColor("#212121")); tvTitle.setId(ID_TITLE); layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); layoutParams.setMargins(Utils.dpToPx(context, 20f), Utils.dpToPx(context, 10f), Utils.dpToPx(context, 20f), 0); linearLayout.addView(tvTitle, layoutParams); // Sub Title TextView tvSubTitle = new TextView(context); tvSubTitle.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14f); tvSubTitle.setMaxLines(2); tvSubTitle.setTextColor(Color.parseColor("#757575")); tvSubTitle.setId(ID_SUBTITLE); layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); layoutParams.setMargins(Utils.dpToPx(context, 20f), 0, Utils.dpToPx(context, 20f), Utils.dpToPx(context, 10f)); linearLayout.addView(tvSubTitle, layoutParams); return linearLayout; }