【问题标题】:How can I make rounded (circled) ImageView box on Android Studio? [duplicate]如何在 Android Studio 上制作圆形(圆形)ImageView 框? [复制]
【发布时间】:2016-07-29 15:31:14
【问题描述】:

我正在尝试在 Android Studio 中创建圆形图像视图而不是方形(如 Whats-app 中的那个)。

这是我的 xml 文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="@drawable/background"
    tools:context="com.example.ska89.xxxxxx.MainActivity">

    <ImageView
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:id="@+id/imageView2"
        android:src="@drawable/logo"
        android:layout_marginTop="64dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:adjustViewBounds="false"
        android:clickable="false" />
</RelativeLayout>

谢谢。

【问题讨论】:

标签: android android-layout


【解决方案1】:

在您的可绘制文件夹中创建一个 xml 文件,例如 circle_shape.xml 并编写如下代码

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">

    <solid
        android:color="@color/colorRound"/>

    <size
        android:width="50dp"
        android:height="50dp"/>
</shape>

然后在你的 imageView 中使用这个 circle_shape.xml 作为背景

<ImageView
    android:layout_width="150dp"
    android:layout_height="150dp"
    android:id="@+id/imageView2"
    android:src="@drawable/logo"
    android:layout_marginTop="64dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:adjustViewBounds="false"
    android:background="@drawable/circle_shape"
    android:clickable="false" />

【讨论】:

    猜你喜欢
    • 2013-08-25
    • 2013-04-18
    • 1970-01-01
    • 2019-07-01
    • 2014-10-05
    • 1970-01-01
    • 2018-06-17
    • 1970-01-01
    • 2014-07-17
    相关资源
    最近更新 更多