Example usage for android.widget LinearLayout HORIZONTAL

List of usage examples for android.widget LinearLayout HORIZONTAL

Introduction

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

Prototype

int HORIZONTAL

To view the source code for android.widget LinearLayout HORIZONTAL.

Click Source Link

Usage

From source file:co.ldln.android.ObjectCreateFragment.java

@Override
public void onReadSchemaResult(final Schema schema) {
    mTextFields = new ArrayList<EditText>();

    // Create the form based on the schema fields
    List<SchemaField> fieldList = new ArrayList<SchemaField>();
    fieldList.addAll(schema.getFields(mActivity));
    Collections.sort(fieldList);/*from  ww w .  j  a  va2s . c  o  m*/
    for (SchemaField field : fieldList) {
        String type = field.getType();
        String label = field.getLabel();

        // Create a linear layout to hold the field
        LinearLayout ll = new LinearLayout(mActivity);
        LayoutParams llParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        ll.setLayoutParams(llParams);
        ll.setOrientation(LinearLayout.HORIZONTAL);

        // TODO: different UI for different field types

        // Default to EditText
        EditText et = new EditText(mActivity);
        LayoutParams etParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        et.setLayoutParams(etParams);
        et.setHint(label);
        if (type.equals("map_location"))
            et.setText(mMapLocation);
        ll.addView(et);
        mTextFields.add(et);

        mFormHolder.addView(ll);
    }

    // Add submit button
    Button b = new Button(mActivity);
    LayoutParams bParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    b.setText("Save");
    b.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                String kvPairs = "";
                JSONObject kvPairsJsonObject = new JSONObject();
                for (EditText et : mTextFields) {
                    String key = et.getHint().toString();
                    String value = et.getText().toString();
                    kvPairsJsonObject.put(key, value);
                }
                kvPairs = kvPairsJsonObject.toString();

                LDLN.saveSyncableObject(mActivity, ObjectCreateFragment.this, schema.getKey(), kvPairs);
            } catch (JSONException e) {
                e.printStackTrace();
                onSaveSyncableObjectResult(false);
            }
        }
    });
    mFormHolder.addView(b);

    Toast.makeText(mActivity,
            "This is a form that's dynamically generated from a syncable object schema. It will soon have handling for dynamic form elements (photo, latlon picker, etc).",
            Toast.LENGTH_LONG).show();
}

From source file:com.ereader.client.ui.view.TabsView.java

public TabsView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs);

    this.mContext = context;

    mDividerMarginTop = (int) (getResources().getDisplayMetrics().density * mDividerMarginTop);
    mDividerMarginBottom = (int) (getResources().getDisplayMetrics().density * mDividerMarginBottom);
    mDividerWidth = (int) (getResources().getDisplayMetrics().density * mDividerWidth);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ViewPagerExtensions, defStyle, 0);

    mDividerColor = a.getColor(R.styleable.ViewPagerExtensions_dividerColor, mDividerColor);

    mDividerMarginTop = a.getDimensionPixelSize(R.styleable.ViewPagerExtensions_dividerMarginTop,
            mDividerMarginTop);/*w w  w. ja  v  a  2 s . c om*/
    mDividerMarginBottom = a.getDimensionPixelSize(R.styleable.ViewPagerExtensions_dividerMarginBottom,
            mDividerMarginBottom);

    mDividerDrawable = a.getDrawable(R.styleable.ViewPagerExtensions_dividerDrawable);

    a.recycle();

    this.setHorizontalScrollBarEnabled(false);
    this.setHorizontalFadingEdgeEnabled(false);

    mContainer = new LinearLayout(context);
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    mContainer.setLayoutParams(params);
    mContainer.setOrientation(LinearLayout.HORIZONTAL);
    mContainer.setGravity(Gravity.CENTER);
    this.addView(mContainer);

}

From source file:com.astuetz.viewpager.extensions.ScrollingTabsView.java

public ScrollingTabsView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs);

    this.mContext = context;

    mDividerMarginTop = (int) (getResources().getDisplayMetrics().density * mDividerMarginTop);
    mDividerMarginBottom = (int) (getResources().getDisplayMetrics().density * mDividerMarginBottom);
    mDividerWidth = (int) (getResources().getDisplayMetrics().density * mDividerWidth);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ViewPagerExtensions, defStyle, 0);

    mDividerColor = a.getColor(R.styleable.ViewPagerExtensions_dividerColor, mDividerColor);

    mDividerMarginTop = a.getDimensionPixelSize(R.styleable.ViewPagerExtensions_dividerMarginTop,
            mDividerMarginTop);/* w w  w  .  j  av a2  s  .  c om*/
    mDividerMarginBottom = a.getDimensionPixelSize(R.styleable.ViewPagerExtensions_dividerMarginBottom,
            mDividerMarginBottom);

    mDividerDrawable = a.getDrawable(R.styleable.ViewPagerExtensions_dividerDrawable);

    a.recycle();

    this.setHorizontalScrollBarEnabled(false);
    this.setHorizontalFadingEdgeEnabled(false);

    mContainer = new LinearLayout(context);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.FILL_PARENT);
    mContainer.setLayoutParams(params);
    mContainer.setOrientation(LinearLayout.HORIZONTAL);

    this.addView(mContainer);

}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.MusicObj.java

public void render(Context context, ViewGroup frame, Obj obj, boolean allowInteractions) {
    JSONObject content = obj.getJson();/*from   w  w  w  .j ava  2s.  c  o m*/
    LinearLayout container = new LinearLayout(context);
    container.setLayoutParams(CommonLayouts.FULL_WIDTH);
    container.setOrientation(LinearLayout.HORIZONTAL);
    container.setGravity(Gravity.CENTER);

    ImageView imageView = new ImageView(context);
    imageView.setImageResource(R.drawable.play);
    imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));

    TextView valueTV = new TextView(context);
    valueTV.setText(asText(content));
    valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    valueTV.setGravity(Gravity.BOTTOM | Gravity.LEFT);
    valueTV.setPadding(4, 0, 0, 0);

    container.addView(imageView);
    container.addView(valueTV);
    frame.addView(container);
}

From source file:com.huyn.demogroup.relativetop.PagerSlidingTabStrip.java

public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    setFillViewport(true);//  ww  w.  j a  v a 2  s  .  c om
    setWillNotDraw(false);

    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    addView(tabsContainer);

    DisplayMetrics dm = getResources().getDisplayMetrics();

    scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
    indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.FILL);

    defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT);
    expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

    if (locale == null) {
        locale = getResources().getConfiguration().locale;
    }
}

From source file:com.wlzndjk.poker.widget.MyHScrollView.java

public MyHScrollView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    //      ACache mCache = ACache.get(MyApplication.getContext());
    //      String asString = mCache.getAsString(MyConstants.SCREENWIDTH);
    //      int screenwidth = Integer.parseInt(asString);
    //      tabWidth = (screenwidth - tabMargins * 2 * 6 - (int) (2 * 30 * screenDensity)) / 6;
    setFillViewport(true);/* w ww  .ja  va  2 s.  c  o m*/
    setWillNotDraw(false);
    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));

    addView(tabsContainer);
}

From source file:de.tobiasbielefeld.solitaire.ui.HighScores.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState); //initialize stuff
    setContentView(R.layout.activity_high_scores);

    ActionBar actionBar = getSupportActionBar();
    layoutScores = (LinearLayout) findViewById(R.id.highScoresLinearLayout1); //load the layouts and textView
    textWonGames = (TextView) findViewById(R.id.highScoresTextViewGamesWon);
    textWinPercentage = (TextView) findViewById(R.id.highScoresTextViewWinPercentage);
    mAdView = (AdView) findViewById(R.id.adView2);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);//ww w  .ja va 2s .c o m

    if (actionBar != null) //set a nice back arrow in the actionBar
        actionBar.setDisplayHomeAsUpEnabled(true);

    loadStatistics();

    for (int i = 0; i < Scores.MAX_SAVED_SCORES; i++) { //for each entry in highScores, add a new view with it
        if (scores.get(i, 0) == 0) //if the score is zero, don't show it
            continue;

        final LinearLayout linearLayout2 = new LinearLayout(this); //new layout for the entry

        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( //create new layout params
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);//
        params.setMargins(0, 0, 0, 10); //add some padding
        linearLayout2.setLayoutParams(params); //and apply them
        linearLayout2.setGravity(Gravity.CENTER); //set gravity
        linearLayout2.setOrientation(LinearLayout.HORIZONTAL); //also set orientation

        TextView textView = new TextView(this); //new textView for the score of the entry
        textView.setText(String.format(Locale.getDefault(), "%s. %s %s ", i + 1, getString( //add the score
                R.string.game_score), scores.get(i, 0)));
        textView.setTextSize(20); //and set text size

        TextView textView2 = new TextView(this); //new textView for the time of the entry
        textView2.setText(String.format(Locale.getDefault(), "%s %02d:%02d:%02d", //add it to the view
                getString(R.string.game_time), scores.get(i, 1) / 3600, (scores.get(i, 1) % 3600) / 60,
                (scores.get(i, 1) % 60)));
        textView2.setTextSize(20); //set size

        linearLayout2.addView(textView); //now add both textViews to the entry layout
        linearLayout2.addView(textView2);
        layoutScores.addView(linearLayout2); //and finally add the new entry layout to the scores layout
    }
}

From source file:com.ntsync.android.sync.activities.AccountListFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    Context context = view.getContext();
    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    linearLayout.setOrientation(LinearLayout.HORIZONTAL);
    linearLayout.setGravity(Gravity.CENTER_HORIZONTAL);

    Button loginBtn = new Button(context);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);//from  w ww  . j  ava 2  s.c  om
    layoutParams.rightMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
            view.getResources().getDisplayMetrics());
    loginBtn.setLayoutParams(layoutParams);
    loginBtn.setText(context.getResources().getText(R.string.accountlist_login_button));
    loginBtn.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            startLoginView();
        }
    });

    Button createAccountBtn = new Button(context);
    createAccountBtn.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    createAccountBtn.setText(context.getResources().getText(R.string.accountlist_creataccount_button));
    createAccountBtn.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            createAccountView();
        }
    });

    linearLayout.addView(loginBtn);
    linearLayout.addView(createAccountBtn);
    ((ViewGroup) this.getListView().getParent()).addView(linearLayout);
    this.getListView().setEmptyView(linearLayout);
}

From source file:de.grobox.transportr.locations.LocationView.java

public LocationView(Context context, AttributeSet attrs) {
    super(context, attrs);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LocationView, 0, 0);
    boolean showIcon = a.getBoolean(R.styleable.LocationView_showIcon, true);
    hint = a.getString(R.styleable.LocationView_hint);
    a.recycle();/* www.  j  a va 2  s.  c  o m*/

    setOrientation(LinearLayout.HORIZONTAL);

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.location_view, this, true);
    ui = new LocationViewHolder(this);

    ui.location.setHint(hint);
    if (!isInEditMode()) {
        adapter = new LocationAdapter(getContext());
        ui.location.setAdapter(adapter);
    }
    ui.location.setOnItemClickListener((parent, view, position, rowId) -> {
        WrapLocation loc = getAdapter().getItem(position);
        if (loc != null)
            onLocationItemClick(loc);
    });
    ui.location.setOnFocusChangeListener(LocationView.this::onFocusChange);
    ui.location.setOnClickListener(view -> LocationView.this.onClick());

    if (showIcon) {
        ui.status.setOnClickListener(v -> {
            getAdapter().resetDropDownLocations();
            LocationView.this.post(this::onClick);
        });
    } else {
        ui.status.setVisibility(GONE);
    }

    // clear text button
    ui.clear.setOnClickListener(v -> clearLocationAndShowDropDown());

    // From text input changed
    ui.location.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if ((count == 1 && before == 0) || (count == 0 && before == 1))
                handleTextChanged(s);
        }

        public void afterTextChanged(Editable s) {
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }
    });
}

From source file:com.paginatedgallery.PaginatedGalleryAdapter.java

@Override
public Object instantiateItem(View collection, int position) {
    LinearLayout layout = new LinearLayout(context);
    layout.setOrientation(LinearLayout.HORIZONTAL);
    layout.setLayoutParams(new LinearLayout.LayoutParams(screenWidth, screenWidth / viewsPerPage));

    int size = images.size();

    //      Log.i(TAG, "Position: "+position + " , Size : "+size);
    for (int i = 0; i < viewsPerPage; i++) {
        final int index = position + (position * (viewsPerPage - 1)) + i;
        Log.i(TAG, "Index: " + index + " , Size : " + size);
        if (index < size) {
            View imageView;//  www. ja  v  a  2 s  . c  o  m
            if (isImageUrl) {
                imageView = new RemoteImageView(context, (String) images.get(index), errorDrawable,
                        errorDrawable, true);
            } else {
                imageView = new ImageView(context);
                ((ImageView) imageView).setImageDrawable((Drawable) images.get(index));
            }

            //            imageView.setTag(index);
            imageView.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (mItemClickListener != null) {
                        mItemClickListener.onItemClick(v, index);
                    }
                }
            });
            imageView.setLayoutParams(new LayoutParams(screenWidth / viewsPerPage, screenWidth / viewsPerPage));
            imageView.setPadding(10, 10, 10, 10);
            layout.addView(imageView);
        }
    }

    ((ViewPager) collection).addView(layout);

    return layout;
}