1.配置文件设置网络权限及http明文请求
<uses-permission android:name="android.permission.INTERNET"/>
//在application中再添加
android:usesCleartextTraffic="true"
2.添加依赖
选择Gradle Scripts下要运行该Activity的模块项目,添加依赖
因为我的项目名是wik2所以就选择build.gradle(Module:******.wik2)然后在依赖里添加以下代码
implementation 'com.android.volley:volley:1.2.1'
implementation 'com.github.bumptech.glide:glide:3.8.0'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.google.code.gson:gson:2.8.6'
3.创建布局
主布局(一个listview和一个button。“主布局名listviewwangluotupian2")
<Button android:id="@+id/button4" android:layout_width="0dp" android:layout_height="wrap_content" android:text="Button" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <ListView android:id="@+id/listview" android:layout_width="409dp" android:layout_height="681dp" android:layout_marginStart="1dp" android:layout_marginTop="1dp" android:layout_marginEnd="1dp" android:layout_marginBottom="1dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/button4" /> </androidx.constraintlayout.widget.ConstraintLayout>
子布局(Imageview,3个textview) 如图
子布局代码("子布局名pictureliulan2")
<ImageView android:id="@+id/imageView" android:layout_width="90dp" android:layou