[英]Selecting photo from gallery for CircleImageView
Hi I am new to java and android studio and have followed some tutorials to get images from the gallery and display it in a circular image view.嗨,我是 java 和 android 工作室的新手,并按照一些教程从图库中获取图像并将其显示在圆形图像视图中。
here is my code:这是我的代码:
private void openImageFrom() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, IMAGE_CODE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == IMAGE_CODE && resultCode == RESULT_OK && data != null && data.getData() != null) {
imageUri = data.getData();
avatar.setImageURI(imageUri);
}
}
The problem is that the circleImageView moves based on the image.问题是 circleImageView 根据图像移动。 I need it to stay in its fixed position.我需要它留在固定的 position 中。 Does anyone know what the problem could be?有谁知道是什么问题?
I am using this dependency in module:app:我在模块中使用此依赖项:应用程序:
implementation 'de.hdodenhof:circleimageview:3.0.1'
And this is my XML这是我的 XML
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/circleImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="0px"
android:src="@drawable/profile_avatar"
app:civ_border_color="@color/DarkGreen"
app:civ_border_overlay="true"
app:civ_border_width="12dp" />
woops fixed my own issue nevermind. woops 解决了我自己的问题,没关系。
changed XML:更改 XML:
android:layout_width="350dp"
android:layout_height="350dp"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.