json - Android - ImageView from URL won't fill_parent in ListView -


i have json, parsing json. results text , image in listview. works fine except 1 thing. trying imageview fill_parent width , wrap_content height. doesn't work..

this layout:

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" >  <textview     android:id="@+id/id"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignparentleft="true"     android:layout_alignparenttop="true"     android:text="large text"     android:textappearance="?android:attr/textappearancelarge" />  <textview     android:id="@+id/title"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignparentleft="true"     android:layout_below="@+id/id"     android:text="large text"     android:textappearance="?android:attr/textappearancelarge" />  <textview     android:id="@+id/created_at"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignparentleft="true"     android:layout_below="@+id/title"     android:text="large text"     android:textappearance="?android:attr/textappearancelarge" />  <textview     android:id="@+id/loves"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignparentleft="true"     android:layout_below="@+id/created_at"     android:text="large text"     android:textappearance="?android:attr/textappearancelarge" />  <textview     android:id="@+id/comments"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignparentleft="true"     android:layout_below="@+id/loves"     android:text="large text"     android:textappearance="?android:attr/textappearancelarge" />  <textview     android:id="@+id/hypes"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignparentleft="true"     android:layout_below="@+id/comments"     android:text="large text"     android:textappearance="?android:attr/textappearancelarge" />  <textview     android:id="@+id/name"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignparentleft="true"     android:layout_below="@+id/hypes"     android:text="large text"     android:textappearance="?android:attr/textappearancelarge" />  <textview     android:id="@+id/byline"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignparentleft="true"     android:layout_below="@+id/name"     android:text="large text"     android:textappearance="?android:attr/textappearancelarge" />  <imageview     android:id="@+id/iv_flag"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:layout_alignparentleft="true"     android:layout_below="@+id/byline" /> 

and if need to, java show image in listview: http://pastebin.com/n0j5gjpe

can me?

try this:

     <imageview         android:id="@+id/iv_flag"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_alignparentleft="true"         android:adjustviewbounds="true"         android:scaletype="fitcenter"/> 

from doc:

android:adjustviewbounds set true if want imageview adjust bounds preserve aspect ratio of drawable. 

try changing scaletype="fitcenter" "centerinside"

if doesn't work, try custom imageview.

public class aspectratioimageview extends imageview {  public aspectratioimageview(context context) {     super(context); }  public aspectratioimageview(context context, attributeset attrs) {     super(context, attrs); }  public aspectratioimageview(context context, attributeset attrs, int defstyle) {     super(context, attrs, defstyle); }  @override protected void onmeasure(int widthmeasurespec, int heightmeasurespec) {     int width = measurespec.getsize(widthmeasurespec);     int height = width * getdrawable().getintrinsicheight() / getdrawable().getintrinsicwidth();     setmeasureddimension(width, height); } 

}

and replace imageview for

     <com.package.aspectratioimageview     android:id="@+id/iv_flag"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:layout_alignparentleft="true"     android:adjustviewbounds="true"     android:scaletype="fitcenter"/> 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -