button to be the same size in java code and xml

This is a discussion on button to be the same size in java code and xml within the Droid Development forums, part of the Droid Hacking category; 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 ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: button to be the same size in java code and xml

  1. Droid Newbie
    goldfish10's Avatar
    Member #
    231295
    Join Date
    Oct 2011
    Posts
    2
    Phone
    HTC - Eris
    #1

    button to be the same size in java code and xml

    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"
    androidrientation="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"
    androidrientation="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"
    androidnClick="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. Sponsor
    DF Advertising
    Join Date
    Nov 2008
    Location
    DroidForums.net
     
     
     
     
  3. Droid Newbie
    goldfish10's Avatar
    Member #
    231295
    Join Date
    Oct 2011
    Posts
    2
    Phone
    HTC - Eris
    #2
    Figured it out... I was able to use just xml.
    Thanks!

Sponsors

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Similar Threads

  1. Java
    By brad92 in forum Droid X General Discussions
    Replies: 1
    Last Post: 06-11-2011, 10:58 AM
  2. Java
    By BaumbachVcV in forum Droid X Hacks
    Replies: 1
    Last Post: 02-21-2011, 04:32 PM
  3. dialer button size
    By Malvado in forum Android App Developers
    Replies: 0
    Last Post: 09-18-2010, 08:47 PM
  4. Java Help
    By J-Buck in forum Off Topic Forum
    Replies: 2
    Last Post: 08-03-2010, 08:53 AM
  5. java help?
    By triiifashions in forum Motorola Droid
    Replies: 0
    Last Post: 04-05-2010, 08:18 AM

Search tags for this page

android button same height

,

android button size xml

,

android java button setheight

,

android layout width droid bionic

,

android:layout weight java

,

button size

,

button size java code

,

get the same size button in java

,

java button coding in android

,

java for droid bionic

,

xml button size

Click on a term to search our site for related topics.

Tags for this Thread