PicassoActivity.kt
package com.example.hoge import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import com.squareup.picasso.Picasso import kotlinx.android.synthetic.main.activity_picassotest.* class PicassoActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_picassotest) Picasso.get() //いらすとやの画像URL .load("https://1.bp.blogspot.com/-kwMHBpDRC98/WMfCOCDhmCI/AAAAAAABClk/0YhKPlx69H8akEluJniMmVV-RoJCRtPvACLcB/s800/onsei_ninshiki_smartphone.png") .resize(300, 300) //表示サイズ指定 .centerCrop() //resizeで指定した範囲になるよう中央から切り出し .into(imageViewtest) //imageViewに流し込み } }
activity_picassotest.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/imageViewtest" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </RelativeLayout>
build.gradle(Module: app)
dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation 'androidx.appcompat:appcompat:1.0.2' implementation 'androidx.core:core-ktx:1.0.2' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' implementation "com.fasterxml.jackson.module:jackson-module-kotlin:2.9.+" + implementation 'com.squareup.picasso:picasso:2.71828' }
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.bs_tender"> + <uses-permission android:name="android.permission.INTERNET" /> + <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.AppCompat.Light.NoActionBar"> <activity android:name=".MatchListActivity" android:label="マッチリスト" android:theme="@style/AppTheme"> </activity> <activity android:name=".MatchActivity" /> <activity android:name=".SplashActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".MainActivity" /> <activity android:name=".SubActivity" /> + <activity android:name=".PicassoActivity" /> </application> </manifest>
@see