Layout Inflater in Android -


there 3 xml files. main.xml has linear layout.
button.xml contains button.
txt.xml contains edit text.
inflate button.xml main.xml.
looks fine.
button has same size in button.xml.
next inflate edit text main.xml has ems=10(android:ems="10").
when run, button changes size same of edit text.
how happen , how overcome problem. code pasted.

main.xml

    <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical"      >      <textview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="@string/hello_world"         tools:context=".first" />     <linearlayout          android:id="@+id/ll"         android:orientation="vertical"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         >     </linearlayout>   </linearlayout> 

button.xml

 <?xml version="1.0" encoding="utf-8"?>       <button xmlns:android="http://schemas.android.com/apk/res/android"         android:id="@+id/button1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="button"         /> 

txt.xml

 <?xml version="1.0" encoding="utf-8"?>      <edittext xmlns:android="http://schemas.android.com/apk/res/android"         android:id="@+id/edittext1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:ems="10"      >          <requestfocus />     </edittext> 

main.java

public class first extends activity {     linearlayout lout;      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_first);         final layoutinflater inf=(layoutinflater)getsystemservice(context.layout_inflater_service);         button btn=(button)inf.inflate(r.layout.button, null);         lout=(linearlayout)findviewbyid(r.id.ll);          lout.addview(btn);         btn.setonclicklistener(new onclicklistener() {              @override             public void onclick(view v) {                 // todo auto-generated method stub                 if(lout.getchildat(5)==null){                     edittext e=(edittext)inf.inflate(r.layout.txt, null);                     lout.addview(e);                 }             }         });      } 

on 5 clicks of button, 5 edit texts show up. moment click button size of button changes in addition edit text formation.

please paste code here, can you. still can set layout_height & layout_width of button 20sp(as per need).

in main.xml file need fix width of layout layout small @ first because textview small. when click on button layout increases per required width edittext , button size increases:

<linearlayout android:id="@+id/ll"                android:orientation="vertical"                android:layout_width="100sp"                android:layout_height="wrap_content" >  </linearlayout> 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -