2016-12-30 57 views
0

我使用毕加索来加载我的可绘制图像,因为它们具有高分辨率。并非所有可绘制的图像都使用毕加索加载

现在的问题是:并非所有图像都加载,有时在活动中显示3个4图像,有时显示4个图像。

下面是代码:

import android.content.Context; 
import android.os.Bundle; 
import android.support.v7.app.AppCompatActivity; 
import android.widget.ImageView; 

import com.squareup.picasso.MemoryPolicy; 
import com.squareup.picasso.Picasso; 




public class SummaryOfTour extends AppCompatActivity { 
    Context context; 

    ImageView imageView ,imageView1,imageView2,imageView3,imageView4,imageView5; 


    static int ms1,ms2,ms3,ms4,ms5; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_summary_of_tour); 

     imageView = (ImageView) findViewById(R.id.img1); 
     imageView1 = (ImageView) findViewById(R.id.img2); 
     imageView2 = (ImageView) findViewById(R.id.img3); 
     imageView3 = (ImageView) findViewById(R.id.img4); 
     imageView4 = (ImageView) findViewById(R.id.img5); 

if(ms1 ==1) { 

    Picasso.with(this) 
      .load(R.drawable.mp1) 
      .resize(1000, 1690) 

      .into(imageView); 


    Picasso.with(this) 
      .load(R.drawable.mp2) 
      .resize(1000, 1690) 
      .into(imageView1); 

    Picasso.with(this) 
      .load(R.drawable.mp3) 
      .resize(1000, 1690) 
      .into(imageView2); 

    Picasso.with(this) 
      .load(R.drawable.mp4) 
      .resize(1000, 1690) 
      .into(imageView3); 

    Picasso.with(this) 
      .load(R.drawable.bg) 
      .resize(1000, 1700) 
      .into(imageView4); 

} 
     else if (ms2 ==1) { 
      Picasso.with(this) 
        .load(R.drawable.mp11) 
        .resize(1000, 1690) 
        .into(imageView); 

      Picasso.with(this) 
        .load(R.drawable.mp22) 
        .resize(1000, 1690) 
        .into(imageView1); 

      Picasso.with(this) 
        .load(R.drawable.mp33) 
        .resize(1000, 1690) 
        .into(imageView2); 

      Picasso.with(this) 
        .load(R.drawable.mp44) 
        .resize(1000, 1690) 
        .into(imageView3); 

      Picasso.with(this) 
        .load(R.drawable.bg) 
        .resize(1000, 1700) 
        .into(imageView4); 

     } 

else if (ms3 ==1) { 
    Picasso.with(this) 
      .load(R.drawable.mp111) 
      .resize(1000, 1690) 
      .into(imageView); 

    Picasso.with(this) 
      .load(R.drawable.mp222) 
      .resize(1000, 1690) 
      .into(imageView1); 

    Picasso.with(this) 
      .load(R.drawable.mp333) 
      .resize(1000, 1690) 
      .into(imageView2); 

    Picasso.with(this) 
      .load(R.drawable.mp444) 
      .resize(1000, 1690) 
      .into(imageView3); 

    Picasso.with(this) 
      .load(R.drawable.bg) 
      .resize(1000, 1700) 
      .into(imageView4); 

} 

else if (ms4 ==1) { 
    Picasso.with(this) 
      .load(R.drawable.mp1111) 
      .resize(1000, 1690) 
      .into(imageView); 

    Picasso.with(this) 
      .load(R.drawable.mp2222) 
      .resize(1000, 1690) 
      .into(imageView1); 

    Picasso.with(this) 
      .load(R.drawable.mp5555) 
      .resize(1000, 1690) 
      .into(imageView2); 

    Picasso.with(this) 
      .load(R.drawable.mp7777) 
      .resize(1000, 1690) 
      .into(imageView3); 

    Picasso.with(this) 
      .load(R.drawable.mp66666) 
      .resize(1000, 1700) 
      .into(imageView4); 

} 





    } 
} 

这里是我的XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.sumo.traffic.InfoOfArtInIsland" 
    android:background="#87E886" 
    android:orientation="vertical"> 
    <ScrollView 
     android:id="@+id/scrollView1" 
     android:layout_width="match_parent" 
     android:layout_height="500dp" > 
     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:weightSum="1"> 



      <LinearLayout 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal" 
       android:layout_marginTop="10dp"> 
       <ImageView 
        android:layout_width="100dp" 
        android:layout_height="100dp" 
        android:id="@+id/imageView5" 
        android:src="@drawable/loaders" 
        android:layout_alignParentTop="true" 
        android:layout_centerHorizontal="true" 
        android:layout_marginLeft="100dp" 
        android:layout_gravity="right" /> 
      </LinearLayout> 



      <RelativeLayout 
       android:layout_width="320dp" 
       android:layout_height="550dp" 
       android:orientation="horizontal" 
       android:layout_marginTop="10dp" 
       android:background="#BEFFB6" 
       android:layout_marginLeft="10dp"> 



       <ImageView 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:id="@+id/img1" 

        android:layout_alignParentTop="true" 
        android:layout_alignStart="@+id/bckgrndViewFlipper1" /> 
      </RelativeLayout> 
      <RelativeLayout 
       android:layout_width="320dp" 
       android:layout_height="550dp" 
       android:orientation="horizontal" 
       android:layout_marginTop="10dp" 
       android:background="#BEFFB6" 
       android:layout_marginLeft="10dp"> 



       <ImageView 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:id="@+id/img2" 

        android:layout_alignParentTop="true" 
        android:layout_alignStart="@+id/bckgrndViewFlipper1" /> 
      </RelativeLayout> 

      <RelativeLayout 
       android:layout_width="320dp" 
       android:layout_height="550dp" 
       android:orientation="horizontal" 
       android:layout_marginTop="10dp" 
       android:background="#BEFFB6" 
       android:layout_marginLeft="10dp"> 



       <ImageView 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:id="@+id/img3" 

        android:layout_alignParentTop="true" 
        android:layout_alignStart="@+id/bckgrndViewFlipper1" /> 
      </RelativeLayout> 


      <RelativeLayout 
       android:layout_width="320dp" 
       android:layout_height="550dp" 
       android:orientation="horizontal" 
       android:layout_marginTop="10dp" 
       android:background="#BEFFB6" 
       android:layout_marginLeft="10dp"> 



       <ImageView 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:id="@+id/img4" 

        android:layout_alignParentTop="true" 
        android:layout_alignStart="@+id/bckgrndViewFlipper1" /> 
      </RelativeLayout> 


      <RelativeLayout 
       android:layout_width="320dp" 
       android:layout_height="550dp" 
       android:orientation="horizontal" 
       android:layout_marginTop="10dp" 
       android:background="#BEFFB6" 
       android:layout_marginLeft="10dp"> 



       <ImageView 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:id="@+id/img5" 

        android:layout_alignParentTop="true" 
        android:layout_alignStart="@+id/bckgrndViewFlipper1" /> 
      </RelativeLayout> 







      <!-- to be commented xml block goes here --> 

      <!-- to be commented xml block goes here --> 

      <!-- to be commented xml block goes here --> 

      <!-- to be commented xml block goes here --> 

      <!-- to be commented xml block goes here --> 

      <!-- to be commented xml block goes here --> 

      <!-- to be commented xml block goes here --> 

      <!-- to be commented xml block goes here --> 

      <!-- to be commented xml block goes here --> 

      <!-- to be commented xml block goes here --> 

      <!-- to be commented xml block goes here --> 

      <!-- to be commented xml block goes here --> 

      <!-- to be commented xml block goes here --> 

      <!-- to be commented xml block goes here --> 

      <!-- to be commented xml block goes here --> 

      <!-- to be commented xml block goes here --> 

      <!-- to be commented xml block goes here --> 

      <!-- to be commented xml block goes here --> 

      <!-- to be commented xml block goes here --> 

      <!-- to be commented xml block goes here --> 

      <!-- to be commented xml block goes here --> 

      <!-- to be commented xml block goes here --> 

      <!-- to be commented xml block goes here --> 

      <!-- to be commented xml block goes here --> 

      <!-- to be commented xml block goes here --> 

     </LinearLayout> 






     <!-- to be commented xml block goes here --> 

     <!-- to be commented xml block goes here --> 

     <!-- to be commented xml block goes here --> 

     <!-- to be commented xml block goes here --> 

     <!-- to be commented xml block goes here --> 




     <!--  <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:orientation="horizontal" 
        android:layout_marginTop="20dp"> 
        <ImageButton 
         android:layout_width="wrap_content" 
         android:layout_height="100dp" 
         android:id="@+id/imageButton3" 
         android:background="@drawable/faqz" 
         android:layout_alignParentBottom="true" 
         android:layout_alignParentStart="true" 
         android:layout_marginBottom="10dp"/> 

       </LinearLayout> 

    --> 




    </ScrollView> 
</LinearLayout> 
+0

我切换到滑翔和图片现在显示,一切都很顺利。我宁愿推荐Glide而不是毕加索。在我看来。 – AndroidProgrammerThatWantsMe

回答

0

定义XML文件中的图片来源.... 机器人:SRC =“@ drawablw/yourimgname “

您的图片扩展名必须为”.png“ 图片名称不能以整数开头。

0
Picasso.with(this) 
      .placeholder(R.drawable.mp1) 
      .resize(1000, 1690) 
      .into(imageView); 

使用.placeholder扩展负载。