英文:
How to set ImageView rounded corners programmatically?
问题
我是Android Studio的新手。我想问一下,我是否可以通过编程方式创建具有圆角的ImageView?因为我想使用它来从数据库加载数据。所以,用户的个人资料图片将显示为圆角。
我的XML如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#F3FFFC">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imgView"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/profilepicture"
/>
</LinearLayout>
</ScrollView>
</LinearLayout>
谢谢您抽出时间阅读我的问题,希望我能解决这个问题:D
英文:
i'm new in Android Studio. I want to ask, can i make ImageView with round corners programmatically? because i want use it to load data from database. So, user profile picture will be appear with rounded corner
my XML is below :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#F3FFFC">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imgView"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/profilepicture"
/>
</LinearLayout>
</ScrollView>
</LinearLayout>
Thank you for your time to read my question, hope i can solve this problem
答案1
得分: 0
<androidx.cardview.widget.CardView
android:layout_width="150dp"
android:layout_height="150dp"
app:cardCornerRadius="20dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher_background" />
</androidx.cardview.widget.CardView>
使用以下依赖项:implementation 'androidx.cardview:cardview:1.0.0'
英文:
<androidx.cardview.widget.CardView
android:layout_width="150dp"
android:layout_height="150dp"
app:cardCornerRadius="20dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher_background" />
</androidx.cardview.widget.CardView>
by using this dependency implementation 'androidx.cardview:cardview:1.0.0'
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论