Android
 Computer >> コンピューター >  >> プログラミング >> Android

Picassoを使用してAndroidで画像のサイズを変更するにはどうすればよいですか?


この例は、AndroidでIを実行する方法を示しています。

ステップ1 − Android Studioで新しいプロジェクトを作成し、[ファイル]⇒[新しいプロジェクト]に移動して、新しいプロジェクトを作成するために必要なすべての詳細を入力します。

ステップ2 − build.gradle(モジュール:アプリ)を開き、次の依存関係を追加します-

implementation 'com.squareup.picasso:picasso:2.5.2'

ステップ3 −次のコードをres / layout/activity_main.xmlに追加します。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="https://schemas.android.com/apk/res/android"
   xmlns:tools="https://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical"
   android:padding="8dp"
   tools:context=".MainActivity">
   <ImageView
      android:id="@+id/imageView"
      android:layout_width="match_parent"
      android:layout_height="match_parent" />
</LinearLayout>

ステップ3 −次のコードをsrc / MainActivity.java

に追加します
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import com.squareup.picasso.Picasso;
public class MainActivity extends AppCompatActivity {
   ImageView imageView;
   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      imageView = findViewById(R.id.imageView);
      String url = "https://images.pexels.com/photos/414612/pexels-photo-414612.jpeg";
      Picasso.with(this).load(url).resize(200, 500).into(imageView);
   }
}

ステップ4 −次のコードをandroidManifest.xmlに追加します

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="https://schemas.android.com/apk/res/android"
   package="app.com.sample">
   <uses-permission android:name="android.permission.INTERNET"/>
   <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/AppTheme">
      <activity android:name=".MainActivity">
         <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
         </intent-filter>
      </activity>
   </application>
</manifest>
アプリケーションを実行してみましょう。実際のAndroidモバイルデバイスをコンピューターに接続していると思います。 Android Studioからアプリを実行するには、プロジェクトのアクティビティファイルの1つを開き、[実行]をクリックします ツールバーのPicassoを使用してAndroidで画像のサイズを変更するにはどうすればよいですか? アイコン。オプションとしてモバイルデバイスを選択し、デフォルトの画面を表示するモバイルデバイスを確認します-

Picassoを使用してAndroidで画像のサイズを変更するにはどうすればよいですか?


  1. Android Picasso Libraryを使用して画像をダウンロードするにはどうすればよいですか?

    この例は、AndroidPicassoライブラリを使用して画像をダウンロードする方法を示しています。 ステップ1 − Android Studioで新しいプロジェクトを作成し、[ファイル]⇒[新しいプロジェクト]に移動して、新しいプロジェクトを作成するために必要なすべての詳細を入力します。 次の依存関係をビルドGradleに追加します(モジュール:app) implementation 'com.squareup.picasso:picasso:2.4.0' ステップ2 −次のコードをres / layout/activity_main.xmlに追加します。 <?x

  2. Androidでアスペクト比を維持するためにImageViewで画像を拡大縮小するにはどうすればよいですか?

    この例は、Androidでアスペクト比を維持するためにImageViewで画像を拡大縮小する方法を示しています。 ステップ1 − Android Studioで新しいプロジェクトを作成し、[ファイル]⇒[新しいプロジェクト]に移動して、新しいプロジェクトを作成するために必要なすべての詳細を入力します。 ステップ2 −次のコードをres / layout/activity_main.xmlに追加します。 <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.