Example usage for android.widget LinearLayout addView

List of usage examples for android.widget LinearLayout addView

Introduction

In this page you can find the example usage for android.widget LinearLayout addView.

Prototype

public void addView(View child) 

Source Link

Document

Adds a child view.

Usage

From source file:com.launcher.silverfish.launcher.appdrawer.TabFragmentHandler.java

/**
 * Loads all tabs from the database./*from  w w w.  j a  v a  2 s.  c o  m*/
 */
public void loadTabs() {
    arrButton = new ArrayList<>();
    arrTabs = new ArrayList<>();

    LinearLayout tabWidget = (LinearLayout) rootView.findViewById(R.id.custom_tabwidget);

    LauncherSQLiteHelper sql = new LauncherSQLiteHelper((App) mActivity.getApplication());
    List<TabTable> tabTables = sql.getAllTabs();

    for (TabTable tabEntry : tabTables) {
        TabInfo tab = new TabInfo(tabEntry);
        arrTabs.add(tab);

        // Create a button for each tab
        Button btn = new Button(mActivity.getApplicationContext());
        btn.setText(tab.getLabel());
        btn.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_TEXT_SIZE);
        arrButton.add(btn);

        // Set the style of the button
        btn.setBackground(settings.getTabButtonStyle());
        btn.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT, 1));
        btn.setTextColor(settings.getFontFgColor());

        // Add the button to the tab widget.
        tabWidget.addView(btn);

        // And create a new tab
        TabHost.TabSpec tSpecFragmentId = tHost.newTabSpec(tab.getTag());
        tSpecFragmentId.setIndicator(tab.getLabel());
        tSpecFragmentId.setContent(new DummyTabContent(mActivity.getBaseContext()));
        tHost.addTab(tSpecFragmentId);
    }

}

From source file:edu.mum.ml.group7.guessasketch.android.EasyPaint.java

private void resetPredictionsView(LinearLayout predictions, boolean showInitLabel) {

    predictions.removeAllViews();/*from  ww w.jav  a2  s . c  o m*/

    if (showInitLabel) {
        TextView tv1 = new TextView(this);
        tv1.setText("Predictions will appear Here");
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        params.weight = 1.f;
        params.gravity = Gravity.CENTER_VERTICAL;

        tv1.setLayoutParams(params);

        tv1.setTextSize(pixels5);
        predictions.addView(tv1);
    }

    if (saveButton != null)
        saveButton.setVisibility(View.INVISIBLE);
    if (loader != null)
        loader.setVisibility(View.INVISIBLE);
}

From source file:terse.a1.TerseActivity.java

void SetContentViewWithHomeButtonAndScroll(View v) {
    Button btn = new Button(this);
    btn.setText("[HOME]");
    // btn.setTextSize(15);
    // btn.setHeight(25);
    // btn.setMaxHeight(25);
    btn.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // Perform action on clicks
            startTerseActivity("/Top", "");
        };/*from   w ww. j a  va  2  s . c  o m*/
    });

    LinearLayout linear = new LinearLayout(this);
    linear.setOrientation(LinearLayout.VERTICAL);
    linear.addView(btn);
    linear.addView(v);

    ScrollView scrollv = new ScrollView(this);
    scrollv.addView(linear);
    setContentView(scrollv);
}

From source file:com.hacktx.android.activities.EventDetailActivity.java

private void setupSpeakers() {
    LinearLayout speakersContainer = (LinearLayout) findViewById(R.id.speakerHolderLayout);
    ArrayList<ScheduleSpeaker> speakers = event.getSpeakerList();
    speakersContainer.removeAllViews();//from   w w w  .j a  v  a2s  .  c o m

    if (speakers.size() == 0) {
        View speakerTitle = findViewById(R.id.speakersTitle);
        speakerTitle.setVisibility(View.GONE);
    }

    for (int child = 0; child < speakers.size(); child++) {
        final ScheduleSpeaker speaker = speakers.get(child);
        View childView = LayoutInflater.from(speakersContainer.getContext())
                .inflate(R.layout.event_detail_speaker, speakersContainer, false);

        CircularImageView speakerIcon = (CircularImageView) childView.findViewById(R.id.speakerIcon);
        Picasso.with(this).load(speaker.getImageUrl()).resize(150, 150).centerCrop()
                .placeholder(R.drawable.ic_profile).into(speakerIcon);
        ((TextView) childView.findViewById(R.id.speakerTitle))
                .setText(speaker.getName() + " | " + speaker.getOrganization());
        ((TextView) childView.findViewById(R.id.speakerDescription)).setText(speaker.getDescription());

        speakersContainer.addView(childView);
    }
}

From source file:com.sdspikes.fireworks.FireworksActivity.java

private void displayInitialState() {
    switchToScreen(R.id.screen_game);//  w  w  w .j  a va 2  s.co  m
    GameState.HandNode currentNode = mTurnData.state.hands.get(mMyId);
    FragmentManager fm = getFragmentManager();
    fragments = new HashMap<>();

    if (fm.findFragmentById(R.id.my_hand) == null) {
        if (currentNode != null) {
            addHandFragment(fm, currentNode, mMyId, mIdToName.get(mMyId), R.id.my_hand);
        } else {
            Log.d(TAG, mMyId);
        }
    }

    if (fm.findFragmentById(R.id.other_hands) == null) {
        while (true) {
            String currentId = currentNode.nextPlayerId;
            if (currentId.equals(mMyId)) {
                break;
            }
            currentNode = mTurnData.state.hands.get(currentId);
            addHandFragment(fm, currentNode, currentId, mIdToName.get(currentId), R.id.other_hands);
        }
    }

    LinearLayout played = (LinearLayout) findViewById(R.id.played_pile);

    played.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            LinearLayout played = (LinearLayout) findViewById(R.id.played_pile);
            mDiscardWidthR2 = played.getMeasuredWidth();

            if (mDiscardWidthR2 != 0) {
                int usableWidth = mDiscardWidthR2 - findViewById(R.id.played_label).getMeasuredWidth();
                mDiscardWidthR1 = mDiscardWidthR2 - findViewById(R.id.discarded_label).getMeasuredWidth();
                for (int i = 1; i < played.getChildCount(); i++) {
                    ViewGroup.LayoutParams params = played.getChildAt(i).getLayoutParams();
                    params.width = usableWidth / 5;
                    played.getChildAt(i).setLayoutParams(params);
                }
                played.getViewTreeObserver().removeOnGlobalLayoutListener(this);

                LinearLayout chooseAttribute = (LinearLayout) findViewById(R.id.chooseAttribute);
                for (int i = 1; i <= 5; i++) {
                    chooseAttribute.addView(makeAttributeTextView(i, null));
                }
                for (GameState.CardColor color : GameState.CardColor.values()) {
                    chooseAttribute.addView(makeAttributeTextView(-1, color));
                }

                // In case all the data is ready already and was just waiting on this.
                updateDisplay();
            }
        }
    });

    createInitialLog();
    ((TextView) findViewById(R.id.log)).setMovementMethod(new ScrollingMovementMethod());
}

From source file:org.cryptsecure.Utility.java

/**
 * Sets the content view with custom title. This is necessary for a holo
 * layout where a custom title bar is normally not permitted.
 * /*from ww w . j  a va 2  s  . c o  m*/
 * @param activity
 *            the activity
 * @param resIdMainLayout
 *            the res id main layout
 * @param resIdTitle
 *            the res id title
 * @return the linear layout
 */
public static LinearLayout setContentViewWithCustomTitle(Activity activity, int resIdMainLayout,
        int resIdTitle) {
    Context context = activity.getApplicationContext();

    // Inflate the given layouts
    LayoutInflater inflaterInfo = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View titleView = (View) inflaterInfo.inflate(resIdTitle, null);
    View mainView = (View) inflaterInfo.inflate(resIdMainLayout, null);

    // Own custom title bar
    //
    // ATTENTION:
    // ADD THIS TO THEME <item name="android:windowNoTitle">true</item>
    activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
    // We can ONLY disable the original title bar because you cannot combine
    // HOLO theme with a CUSTOM title bar :(
    // So we make our own title bar instead!

    // ALSO REMOVE TITLEBAR FROM APPLICATION AT STARTUP:
    // ADD TO MANIFEST
    // android:theme="@android:style/Theme.NoTitleBar"

    // THE FOLLOWING IS NOT WORKING WITH HOLO
    // requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    // setContentView(R.layout.activity_main);
    // getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
    // R.layout.title_main);

    // Create title layout
    LinearLayout.LayoutParams lpTitle = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    LinearLayout titleLayout = new LinearLayout(context);
    titleLayout.setOrientation(LinearLayout.VERTICAL);
    titleLayout.addView(titleView);
    titleLayout.setLayoutParams(lpTitle);

    // Create main layout
    LinearLayout.LayoutParams lpMain = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT);
    LinearLayout mainLayout = new LinearLayout(context);
    mainLayout.setOrientation(LinearLayout.VERTICAL);
    mainLayout.addView(mainView);
    mainLayout.setLayoutParams(lpMain);

    // Create root outer layout
    LinearLayout outerLayout = new LinearLayout(context);
    outerLayout.setOrientation(LinearLayout.VERTICAL);
    outerLayout.addView(titleLayout);
    outerLayout.addView(mainLayout);

    // outerLayout.setBackgroundColor(Color.rgb(255, 0, 0));
    // mainLayout.setBackgroundColor(Color.rgb(0, 255, 0));
    // titleLayout.setBackgroundColor(Color.rgb(0, 0, 255));

    // lpSectionInnerLeft.setMargins(20, 5, 0, 15);
    // LinearLayout.LayoutParams lpSectionInnerRight = new
    // LinearLayout.LayoutParams(
    // 90, LinearLayout.LayoutParams.WRAP_CONTENT, 0f);
    // lpSectionInnerRight.setMargins(0, 5, 15, 15);

    // After setting NO TITLE .. apply the layout
    activity.setContentView(outerLayout);

    return mainLayout;
}

From source file:br.org.funcate.dynamicforms.views.GPictureView.java

/**
 * @param fragmentDetail        the fragment detail  to use.
 * @param attrs                 attributes.
 * @param requestCode           the code for starting the activity with result.
 * @param parentView            parent// w  ww.j ava  2 s  .  c o m
 * @param label                 label
 * @param pictures              the value are the ids and binary data of the images.
 * @param constraintDescription constraints
 */
public GPictureView(final FragmentDetail fragmentDetail, AttributeSet attrs, final int requestCode,
        LinearLayout parentView, String label, Map<String, Map<String, String>> pictures,
        String constraintDescription) {
    super(fragmentDetail.getActivity(), attrs);

    thumbnailWidth = fragmentDetail.getActivity().getResources().getInteger(R.integer.thumbnail_width);
    thumbnailHeight = fragmentDetail.getActivity().getResources().getInteger(R.integer.thumbnail_height);

    mFragmentDetail = fragmentDetail;

    _pictures = pictures;

    PICTURE_VIEW_RESULT = requestCode;

    final FragmentActivity activity = fragmentDetail.getActivity();
    LinearLayout textLayout = new LinearLayout(activity);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    layoutParams.setMargins(10, 10, 10, 10);
    textLayout.setPadding(10, 5, 10, 5);
    textLayout.setLayoutParams(layoutParams);
    textLayout.setOrientation(LinearLayout.VERTICAL);
    parentView.addView(textLayout);

    TextView textView = new TextView(activity);
    textView.setLayoutParams(
            new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    textView.setPadding(2, 2, 2, 2);
    String t = label.replace(UNDERSCORE, " ").replace(COLON, " ") + " " + constraintDescription;
    textView.setText(t);
    textView.setTextColor(activity.getResources().getColor(R.color.formcolor));
    textLayout.addView(textView);

    final Button button = new Button(activity);
    button.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    button.setPadding(15, 5, 15, 5);
    button.setText(R.string.take_picture);
    textLayout.addView(button);

    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            Intent cameraIntent = new Intent(activity, CameraActivity.class);

            cameraIntent.putExtra(FormUtilities.MAIN_APP_WORKING_DIRECTORY,
                    fragmentDetail.getWorkingDirectory());

            fragmentDetail.startActivityForResult(cameraIntent, requestCode);
        }
    });

    ScrollView scrollView = new ScrollView(activity);
    ScrollView.LayoutParams scrollLayoutParams = new ScrollView.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    scrollView.setLayoutParams(scrollLayoutParams);
    scrollView.setHorizontalScrollBarEnabled(true);
    scrollView.setOverScrollMode(HorizontalScrollView.OVER_SCROLL_ALWAYS);
    parentView.addView(scrollView);

    imageLayout = new LinearLayout(activity);
    LinearLayout.LayoutParams imageLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    imageLayout.setLayoutParams(imageLayoutParams);
    imageLayout.setPadding(15, 5, 15, 5);
    imageLayout.setOrientation(LinearLayout.HORIZONTAL);
    imageLayout.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
    scrollView.addView(imageLayout);

    updateValueForm();
    try {
        refresh(activity);
    } catch (Exception e) {
        //GPLog.error(this, null, e);
        e.printStackTrace();
        Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_LONG).show();
    }
}

From source file:com.geoffreybuttercrumbs.arewethereyet.DrawerFragment.java

private void recent() {
    LayoutInflater inflater = getActivity().getLayoutInflater();
    SharedPreferences prefs = getActivity().getSharedPreferences("AreWeThereYet", Context.MODE_WORLD_WRITEABLE);

    for (int i = 1; i <= 5; i++) {
        Location location = new Location("POINT_LOCATION");
        String address = prefs.getString(POINT_ADDRESS_KEY + i, "");
        location.setLatitude(0);/*from   w  w w .j  ava  2s  .c  o m*/
        location.setLongitude(0);
        if (prefs.contains(POINT_LATITUDE_KEY + i)) {
            location.setLatitude(prefs.getFloat(POINT_LATITUDE_KEY + i, 0));
        }
        if (prefs.contains(POINT_LONGITUDE_KEY + i)) {
            location.setLongitude(prefs.getFloat(POINT_LONGITUDE_KEY + i, 0));
        }

        LinearLayout RecentParent = (LinearLayout) V.findViewById(R.id.group_recent);
        View Recent = inflater.inflate(R.layout.saved_item, null);
        Recent.setOnClickListener(this);

        CharSequence name;
        if (!address.equals("")) {
            name = address;
            ((TextView) Recent.findViewById(R.id.savedLabel)).setTextColor(0xDDFFFFFF);
            ((CompoundButton) Recent.findViewById(R.id.saveCB)).setOnCheckedChangeListener(this);
        } else {
            name = "No Recent Alarms";
            ((TextView) Recent.findViewById(R.id.savedLabel)).setTextColor(0xDD999999);
            Recent.findViewById(R.id.saveCB).setEnabled(false);
        }

        ((TextView) Recent.findViewById(R.id.savedLabel)).setText(name);
        ((TextView) Recent.findViewById(R.id.savedLabel)).setTextSize(14);
        Recent.findViewById(R.id.saveCB).setTag(i);
        Recent.setId(i);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        RecentParent.setLayoutParams(params);
        RecentParent.addView(Recent);
    }
}

From source file:com.example.damerap_ver1.IntroVideoActivity.java

/**
* Create the view in which the video will be rendered.
*//* w  ww  . jav  a 2 s .  c o m*/
private void setupView() {
    LinearLayout lLinLayout = new LinearLayout(this);
    lLinLayout.setId(1);
    lLinLayout.setOrientation(LinearLayout.VERTICAL);
    lLinLayout.setGravity(Gravity.CENTER);
    lLinLayout.setBackgroundColor(Color.BLACK);

    LayoutParams lLinLayoutParms = new LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT);
    lLinLayout.setLayoutParams(lLinLayoutParms);

    this.setContentView(lLinLayout);

    RelativeLayout lRelLayout = new RelativeLayout(this);
    lRelLayout.setId(2);
    lRelLayout.setGravity(Gravity.CENTER);
    lRelLayout.setBackgroundColor(Color.BLACK);
    android.widget.RelativeLayout.LayoutParams lRelLayoutParms = new android.widget.RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT);
    lRelLayout.setLayoutParams(lRelLayoutParms);
    lLinLayout.addView(lRelLayout);

    mVideoView = new VideoView(this);
    mVideoView.setId(3);
    android.widget.RelativeLayout.LayoutParams lVidViewLayoutParams = new android.widget.RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    lVidViewLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
    mVideoView.setLayoutParams(lVidViewLayoutParams);
    lRelLayout.addView(mVideoView);

    mProgressBar = new ProgressBar(this);
    mProgressBar.setId(4);
    android.widget.RelativeLayout.LayoutParams lProgressBarLayoutParms = new android.widget.RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    lProgressBarLayoutParms.addRule(RelativeLayout.CENTER_IN_PARENT);
    mProgressBar.setLayoutParams(lProgressBarLayoutParms);
    lRelLayout.addView(mProgressBar);

    mProgressMessage = new TextView(this);
    mProgressMessage.setId(5);
    android.widget.RelativeLayout.LayoutParams lProgressMsgLayoutParms = new android.widget.RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    lProgressMsgLayoutParms.addRule(RelativeLayout.CENTER_HORIZONTAL);
    lProgressMsgLayoutParms.addRule(RelativeLayout.BELOW, 4);
    mProgressMessage.setLayoutParams(lProgressMsgLayoutParms);
    mProgressMessage.setTextColor(Color.LTGRAY);
    mProgressMessage.setTextSize(TypedValue.COMPLEX_UNIT_PT, 8);
    mProgressMessage.setText("...");
    lRelLayout.addView(mProgressMessage);
}

From source file:org.quantumbadger.redreader.activities.InboxListingActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {

    PrefsUtility.applyTheme(this);
    super.onCreate(savedInstanceState);

    final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    final boolean solidblack = PrefsUtility.appearance_solidblack(this, sharedPreferences)
            && PrefsUtility.appearance_theme(this, sharedPreferences) == PrefsUtility.AppearanceTheme.NIGHT;

    getActionBar().setHomeButtonEnabled(true);
    getActionBar().setDisplayHomeAsUpEnabled(true);

    final String title;

    isModmail = getIntent() != null && getIntent().getBooleanExtra("modmail", false);

    if (!isModmail) {
        title = getString(R.string.mainmenu_inbox);
    } else {//w  w  w  .jav  a  2 s.co m
        title = getString(R.string.mainmenu_modmail);
    }

    OptionsMenuUtility.fixActionBar(this, title);

    headerItems = PrefsUtility.appearance_comment_header_items(this, sharedPreferences);
    headerItems.remove(PrefsUtility.AppearanceCommentHeaderItems.SCORE);

    final LinearLayout outer = new LinearLayout(this);
    outer.setOrientation(android.widget.LinearLayout.VERTICAL);

    if (solidblack) {
        outer.setBackgroundColor(Color.BLACK);
    }

    loadingView = new LoadingView(this, getString(R.string.download_waiting), true, true);

    notifications = new LinearLayout(this);
    notifications.setOrientation(android.widget.LinearLayout.VERTICAL);
    notifications.addView(loadingView);

    final ListView lv = new ListView(this);

    lv.setSmoothScrollbarEnabled(false);
    lv.setVerticalFadingEdgeEnabled(false);

    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            final Object item = lv.getAdapter().getItem(position);

            if (item != null && item instanceof RedditPreparedInboxItem) {
                ((RedditPreparedInboxItem) item).handleInboxClick(InboxListingActivity.this);
            }
        }
    });

    adapter = new InboxListingAdapter(this, this);
    lv.setAdapter(adapter);

    registerForContextMenu(lv);

    outer.addView(notifications);
    outer.addView(lv);

    makeFirstRequest(this);

    setContentView(outer);
}