J. Arenas
J. Arenas

Reputation: 493

How to control addView to a layout

I add a graphview programatically :

    LinearLayout.LayoutParams Lparams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, p.y/2);

//same result with fill_parent or match_parent

    Lparams.gravity = Gravity.LEFT;

    firstGraph.setPadding(10, 0, 10, 0);

    firstGraph.setLayoutParams(Lparams);

    LinearLayout RelLayout = (LinearLayout) findViewById(R.id.relLayout);

    RelLayout.setGravity(Gravity.LEFT);
    RelLayout.addView(firstGraph, 0);

I obtain this: Problem

What i want is to eliminate that left gap of the graphview, I don't know why is there, I only set a padding of 10 that is what you have in right side.

Any Suggestions? Thansk in advance.

the layout xml:

            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/relLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="left"
        android:orientation="vertical" >

<Button
    android:id="@+id/button3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button" />



</LinearLayout>

Upvotes: 0

Views: 240

Answers (2)

user
user

Reputation: 87064

That space most likely appears because it is the space reserved for the axis labels(and as you probably don't set any labels it's an empty space). If you do need to remove it you'll have to modify the graph view's code and change the values in GraphViewConfig(as those seem to be the values used).

Upvotes: 1

rahul
rahul

Reputation: 6487

setPadding(int left, int top, int right, int bottom) is the sytax of setPadding. The first argument is for the left padding. You are giving 10. Try setPadding(0, 0, 10, 0)

Upvotes: 0

Related Questions