2017-09-12 1 views
-1

ピカソを使用しているimageViewにURL(有効)からイメージをロードしようとしています。私はGradleの経由ピカソlibaryを追加したと私は両方を追加しました:Picasso Not Loading Image from url

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
<uses-permission android:name="android.permission.INTERNET" /> 

私のコードに、他の多くのユーザーが指摘しています。 私は間違いがなく、10秒以上経っても何もしません。

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); 
} 

と私の活動の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> 

それが動作するように取得する方法上の任意のアイデアここで は私のJavaメソッドのですか? 私は確かに私がどこかで間違いを犯していると確信しています。私はここで2つのことをしようとすることをお勧め

+0

グライドライブラリを試してみてください...いくつかの時間が私はピカソを使用して、このような問題に直面しているが、それはglide.httpsで解決://github.com/bumptech/glide –

+0

は親切デバイスまたはAPIを述べましたレベル – sivaprakash

+1

XMLをチェックしてください。間違いはXMLファイルにあると思います。なぜあなたは相対レイアウトを使用するよりも制約レイアウトを使用していますか? –

答えて

0

あなたの親相対的なレイアウトの高さと幅があります0dpですが、なぜchildLayout画像。だからを表示できません(ImageViewの)、相対レイアウトの高さと幅wrap_contentまたはmatch_parentを設定する必要があります。そのように:

<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> 
0

あなたがあなたの相対的なレイアウトに制約の下に使用する必要があります画像が制約レイアウトやセンターを使用したい場合は...

app:layout_constraintBottom_toBottomOf="parent" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintTop_toTopOf="parent" 
+0

制約レイアウトが親として使用されたので、実際には親全体をカバーしていました。 –

0

1. Picassoが正常に動作していることを確認するための画像のプレースホルダを提供します。

Picasso.with(context) 
     .load(imageUrl) 
     .placeholder(R.drawable.image_name) 

2.マニフェストでuse-permissionを2回書きます。 [私はこれがクレイジーに聞こえるかもしれ知っているが、このバグを持っていたグレード/スタジオのいくつかのバージョンがあった]

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
<uses-permission android:name="android.permission.INTERNET"/> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
<uses-permission android:name="android.permission.INTERNET"/> 
+0

なぜアクセス権を2回追加していますか? Singleyを追加すると仕事ができます。 – Ghimire