button to be the same size in java code and xml

Discussion in 'Android Hacks and Help' started by goldfish10, Oct 24, 2011.

  1. goldfish10
    Offline

    goldfish10 New Member

    Joined:
    Oct 24, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    I have a button I created in Xml and that works great.
    I am attempting to generate the same button in java code, but I am having trouble.
    It seems the button height is larger than the the xml code.
    I have tried the Button.setHeight, but it does not seem to have any affect.
    Perhaps we need to Inflate the XML.
    I have included the Xml and java code.
    So, I would like get the java code to match the xml.

    login2.xml code...
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:eek:rientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:weightSum="1"
    android:scrollbars="vertical"
    android:scrollbarAlwaysDrawHorizontalTrack="true">

    <LinearLayout android:id="@+id/LinearLayout3"
    android:eek:rientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    android:layout_marginLeft="4dp"
    android:layout_marginBottom="4dp"
    android:layout_marginRight="4dp" >
    <TextView android:id="@+id/text_one"
    android:text=""
    android:textSize="8pt"
    android:textColor="#000000"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="right"
    android:layout_weight="5" />
    <Button android:id="@+id/ButtonSubmit"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:background="@drawable/submit"
    android:eek:nClick="submitLogin2"
    android:layout_weight="5" />
    </LinearLayout>
    </LinearLayout>


    public void mySubmit() {
    LinearLayout parent = new LinearLayout(this);
    parent.setOrientation(LinearLayout.VERTICAL);

    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams (LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 0.9f);

    LinearLayout child = new LinearLayout(this);
    child.setOrientation(LinearLayout.HORIZONTAL);
    child.setGravity(Gravity.RIGHT);
    child.setPadding(162, 0, 0, 200);
    Button b = new Button(this);
    b.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    b.setHeight(5);
    b.setBackgroundResource(R.drawable.submit);

    child.addView(b, lp);
    parent.addView(child);

    this.setContentView(parent);

    b.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
    showDialog(0);
    t = new Thread() {
    public void run() {
    System.exit(0);
    }
    };
    t.start();
    }
    });
    return;
    }
  2. goldfish10
    Offline

    goldfish10 New Member

    Joined:
    Oct 24, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Figured it out... I was able to use just xml.
    Thanks!
Search tags for this page

android buttons same size

,
android how to get same size button
,
android layout 3 button same size
,
android xml button size
,
android+button+same length
,
button.setheight android
,
java buttons all same sizes
,
set height for button in android java
,
set height from java code for button view in android
,
xml button height