android - The height of text view doesn't change dynamically -


i wrote android program. in right hand there 4 little green boxes (text view). set height wrap dynamically change height , cover whole layout , if add textview height decrease.

graphic:

graphic

layout_file.xml:

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" >  <linearlayout     android:layout_width="0dip"     android:layout_height="300dip"     android:orientation="vertical" android:layout_weight="0.75 ">      <linearlayout         android:layout_width="match_parent"         android:layout_height="0dip" android:layout_weight="0.25">          <textview             android:layout_width="0dip"             android:layout_height="fill_parent"             android:layout_margin="2dip"             android:layout_weight="0.25"             android:background="#00ffff" />          <textview             android:layout_width="0dip"             android:layout_height="fill_parent"             android:layout_margin="2dip"             android:layout_weight="0.25"             android:background="#00ff00" />     </linearlayout>      <textview         android:layout_width="match_parent"         android:layout_height="0dip"         android:layout_margin="2dip"         android:background="#00ffff" android:layout_weight="0.25"/>      <textview         android:layout_width="match_parent"         android:layout_height="0dip"         android:layout_margin="2dip"         android:background="#00ffff" android:layout_weight="0.25"/>      <linearlayout         android:layout_width="match_parent"         android:layout_height="0dib" android:layout_weight="0.25">          <textview             android:layout_width="0dip"             android:layout_height="fill_parent"             android:layout_margin="2dip"             android:layout_weight="0.2"             android:background="#00ffff" />          <textview             android:layout_width="0dip"             android:layout_height="fill_parent"             android:layout_margin="2dip"             android:layout_weight="0.7"             android:background="#00ff00" />     </linearlayout>  </linearlayout>  <linearlayout     android:layout_width="0dip"     android:layout_height="300dip"     android:orientation="vertical" android:layout_weight="0.25">      <textview         android:layout_width="match_parent"         android:layout_height="120dip"         android:layout_margin="2dip"         android:background="#00ff00" />      <linearlayout         android:layout_width="match_parent"         android:layout_height="fill_parent"         android:orientation="vertical" >          <textview             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:layout_margin="2dip"             android:background="#00ff0b" />          <textview             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:layout_margin="2dip"             android:background="#00ff0b" />          <textview             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:layout_margin="2dip"             android:background="#00ff0b" />          <textview             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:layout_margin="2dip"             android:background="#00ff0b" />       </linearlayout>  </linearlayout> 


java code:

package abc.sara.app.mystartu1;    import android.app.activity;   import android.os.bundle;    public class mystartup1 extends activity {   /** called when activity first created. */   @override   public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.main);   } } 

well okey found problem. try play more around weights , textviews.

  • set your right, green textviews android:layout_height="match_parent"
  • set weights android:layout_weight="1"
  • set highest android:layout_weight="0.7"

now should that:

<linearlayout     android:layout_width="match_parent"     android:layout_height="fill_parent"     android:orientation="vertical">      <textview         android:layout_width="match_parent"         android:layout_height="match_parent"         android:layout_margin="2dp"         android:background="#00ff0b"         android:layout_weight="0.7" />      <textview         android:layout_width="match_parent"         android:layout_height="match_parent"         android:layout_margin="2dp"         android:background="#00ff0b"         android:layout_weight="1" />      <textview         android:layout_width="match_parent"         android:layout_height="match_parent"         android:layout_margin="2dp"         android:background="#00ff0b"         android:layout_weight="1" />      <textview         android:layout_width="match_parent"         android:layout_height="match_parent"         android:layout_margin="2dp"         android:background="#00ff0b"         android:layout_weight="1" />      <textview         android:layout_width="match_parent"         android:layout_height="match_parent"         android:layout_margin="2dp"         android:background="#00ff0b"         android:layout_weight="1"         android:id="@+id/textview" />    </linearlayout> 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -