java - Incorrectly displayed view created programmaticaly(android) -


sorry english. create views programmatically, on devices displayed wrong. have layout in programmatically add spinner. xml:

container - it's layout create spinner(programmatically)

spinnerl - here add spinner

<linearlayout         android:id="@+id/container"         android:layout_width="match_parent"         android:orientation="horizontal"         android:background="#26ffffff"         android:layout_height="wrap_content">          <linearlayout             android:id="@+id/spinnerl"             android:orientation="horizontal"             android:layout_width="match_parent"             android:layout_height="match_parent"             android:layout_alignparenttop="true"             android:layout_weight="0.2"             android:layout_centerhorizontal="true" />          <relativelayout             android:id="@+id/spinneropen"             android:layout_width="match_parent"             android:layout_marginright="5dp"             android:layout_weight="0.8"             android:layout_height="match_parent">              <imageview                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:id="@+id/spinnerimage"                 android:layout_centervertical="true"                 android:layout_centerhorizontal="true" />            </relativelayout>      </linearlayout> 

here create , add spinner:

//here set margins view linearlayoutg = convertview.findviewbyid(r.id.container);  linearlayoutg.setbackgroundcolor(color.parsecolor("#26ffffff"));  linearlayout.layoutparams layoutparams = new linearlayout.layoutparams(linearlayout.layoutparams.match_parent, linearlayout.layoutparams.wrap_content);  layoutparams.setmargins(10, 0, 10, 30); linearlayoutg.setlayoutparams(layoutparams);  //here create spinner view linearlayout = convertview.findviewbyid(r.id.spinnerl); final spinner spinner = new spinner(context);  spinner.setlayoutparams(new linearlayout.layoutparams(linearlayout.layoutparams.match_parent, linearlayout.layoutparams.match_parent));  //code  ((linearlayout) linearlayout).addview(spinner); 

(sorry links, don't have 15 reputation)

result on android 4.0.1

result on android 5+

if use static size, this:

linearlayout.layoutparams layoutparams = new linearlayout.layoutparams(             linearlayout.layoutparams.match_parent, 120); 

here's happens

result on android 4.0.1

result on android 5+

well can see in code :

spinner.setlayoutparams(new linearlayout.layoutparams(linearlayout.layoutparams.match_parent, linearlayout.layoutparams.match_parent)); 

you setting height match_parent. have no idea why working on 4.0.1 change code this:

spinner.setlayoutparams(new linearlayout.layoutparams(linearlayout.layoutparams.match_parent, linearlayout.layoutparams.wrap_content)); 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -