android - Picasso Not Loading image from url -


so trying load image url(its valid) imageview using picasso. have added picasso libary via gradle , have added both:

<uses-permission android:name="android.permission.access_network_state"/> <uses-permission android:name="android.permission.internet" />  

to code many other users have pointed out. don't have errors , doesn't after 10+ seconds. here java method:

imageview image; @override protected void oncreate(bundle savedinstancestate) {      super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);     image=(imageview)findviewbyid(r.id.image);     picasso.with(getapplicationcontext()).load("http://i.imgur.com/dvpvklr.png").into(image); } 

and activity xml:

<android.support.constraint.constraintlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.benhouse.testproj.mainactivity">   <relativelayout     android:layout_width="0dp"     android:layout_height="0dp"     tools:layout_editor_absolutey="8dp"     tools:layout_editor_absolutex="8dp">      <imageview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_centervertical="true"         android:layout_centerhorizontal="true"         android:id="@+id/image"/> </relativelayout> 

any ideas on how work? i'm sure i'm making obvious mistake somewhere.

your parent relative layout height , width 0dp that's why childlayout(imageview) unable show image .so, need set relative layout height , width wrap_content or match_parent. that:

<android.support.constraint.constraintlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.benhouse.testproj.mainactivity">   <relativelayout     android:layout_width="match_parent"     android:layout_height="match_parent"     tools:layout_editor_absolutey="8dp"     tools:layout_editor_absolutex="8dp">      <imageview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_centervertical="true"         android:layout_centerhorizontal="true"         android:id="@+id/image"/> </relativelayout> 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -