compile 'com.squareup.picasso:picasso:2.5.2'
<uses-permission android:name="android.permission.INTERNET"/>
<?xml version="1.0" encoding="utf-8"?> | |
<RelativeLayout android:id="@+id/root_layout" | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context=".MainActivity" > | |
<ImageView | |
android:id="@+id/main_image" | |
android:layout_width="200dp" | |
android:layout_height="200dp" | |
android:layout_alignParentTop="true" | |
android:layout_centerInParent="true" /> | |
</RelativeLayout> |
public class DetailedImageActivity extends AppCompatActivity { | |
static final String IMAGE_URL = "imageUrl"; | |
public static void launchActivity(Context context, String imageUrl) { | |
Intent intent = new Intent(context, ImageDetailActivity.class); | |
intent.putExtra(IMAGE_URL, imageUrl); | |
context.startActivity(intent); | |
} | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
getSupportActionBar().hide(); | |
setContentView(R.layout.activity_detailed_image); | |
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); | |
Intent intent = getIntent(); | |
String imageUrl = intent.getStringExtra(IMAGE_URL); | |
ImageView imageView = new ImageView(this); | |
Picasso.with(this).load(imageUrl).into(imageView); | |
FrameLayout frameLayout = (FrameLayout) findViewById(R.id.image_detail_layout); | |
frameLayout.addView(imageView); | |
} | |
} |
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
ImageView mainImage = (ImageView) findViewById(R.id.main_image); | |
final String imageUrl = "https://raw.githubusercontent.com/mapyo/sample/master/image/nyannyan.png"; | |
Picasso.with(this).load(imageUrl).into(mainImage); | |
mainImage.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
ImageDetailActivity.launchActivity(v.getContext(), imageUrl); | |
} | |
}); | |
} | |
} |