标签:4.12 glide androidx implementation navigation ImageView com
默认
图片是放在ImageView控件里边的
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:background="#ffff33"
android:src="@drawable/img">
</ImageView>
fitXY
scaleType=“fitXY”
拉伸图片使得图片占据整个控件
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:background="#ffff33"
android:src="@drawable/img"
android:scaleType="fitXY">
</ImageView>
fitCenter
保持图片原有宽高比,成比例拉伸,直到长或宽到达边界(貌似和默认的效果一样)
<ImageView
android:id="@+id/iv_2"
android:layout_below="@+id/iv_1"
android:layout_marginTop="20dp"
android:layout_width="400dp"
android:layout_height="200dp"
android:background="#ffff33"
android:src="@drawable/img"
android:scaleType="fitCenter">
</ImageView>
centerCrop
保持宽高比一直扩大,直到全部覆盖,超过的部分被裁减
<ImageView
android:id="@+id/iv_2"
android:layout_below="@+id/iv_1"
android:layout_marginTop="20dp"
android:layout_width="400dp"
android:layout_height="200dp"
android:background="#ffff33"
android:src="@drawable/img"
android:scaleType="centerCrop">
</ImageView>
网络图片
repositories {
google()
mavenCentral()
}
dependencies {
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
}
如果有repositories、dependencies块就将里边两行代码加到块里边,不然就直接复制进去
repositories {
google()
mavenCentral()
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.navigation:navigation-fragment:2.2.2'
implementation 'androidx.navigation:navigation-ui:2.2.2'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
}
监听设置网络图片
public class ImageViewActivity extends AppCompatActivity {
private ImageView iv1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image_view);
iv1=findViewById(R.id.iv_1);
Glide.with(this).load("https://www.baidu.com/i00mg/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png").into(iv1);
}
}
除此之外,还不能显示出来,没有网络权限
Permission denied (missing INTERNET permission?)
AndroidManifest.xml里面加权限
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
SUCCESS
标签:4.12,glide,androidx,implementation,navigation,ImageView,com 来源: https://blog.csdn.net/WA_MC/article/details/115426021
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。