【问题标题】:How to a circular Image on ImageView and relative layout using xml [duplicate]如何使用 xml 在 ImageView 和相对布局上创建圆形图像 [重复]
【发布时间】:2020-07-06 16:59:41
【问题描述】:

如何在 Image 视图中添加圆形图像,如下图所示:

这是我的代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    xmlns:card_view="http://schemas.android.com/apk/res-auto">

    <androidx.cardview.widget.CardView
        android:id="@+id/card_view"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_margin="3dp"
        card_view:cardBackgroundColor="@color/colorwhite"
        card_view:cardCornerRadius="8dp"
        card_view:cardUseCompatPadding="false"
        card_view:elevation="15dp">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="130dp"
            android:layout_gravity="center_horizontal"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/flag"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentRight="true"
                android:scaleType="fitXY"
                android:src="@drawable/mac_img" />

            <TextView
                android:id="@+id/titleTxt"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_marginTop="85dp"
                android:textStyle="bold"
                android:textColor="@color/colorwhite"
                android:layout_centerHorizontal="true" />


        </RelativeLayout>


    </androidx.cardview.widget.CardView>

</LinearLayout>

当我尝试添加一个文本视图时,就像图像中显示的 Closed 一样,所以我只需要一种方法来做到这一点,以便像图中那样放置小部件..

【问题讨论】:

标签: android xml


【解决方案1】:

好的,我通过添加一些边距解决了这个问题我希望有人给我一个建议,这是完整的代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:card_view="http://schemas.android.com/apk/res-auto">

    <androidx.cardview.widget.CardView
        android:id="@+id/card_view"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_margin="3dp"
        card_view:cardBackgroundColor="@color/colorwhite"
        card_view:cardCornerRadius="8dp"
        card_view:cardUseCompatPadding="false"
        card_view:elevation="15dp">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="130dp"
            android:layout_gravity="center_horizontal"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/flag"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentRight="true"
                android:scaleType="fitXY"
                android:src="@drawable/mac_img" />

            <TextView
                android:id="@+id/titleTxt"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_marginTop="85dp"
                android:textStyle="bold"
                android:textColor="@color/colorwhite"
                android:layout_centerHorizontal="true" />


        </RelativeLayout>

        <com.cuboid.cuboidcirclebutton.CuboidButton
            android:layout_width="70dp"
            android:layout_height="70dp"
            app:cub_border_color="@color/color_64b5f6"
            app:cub_border_radius="4dp"
            android:layout_marginTop="85dp"
            android:layout_marginLeft="30dp"
            app:cub_color="@color/colorwhite"
            app:cub_hover_color="@color/color_0288D1"
            app:cub_icon="@drawable/eat"
            app:cub_riple_effect="true" />


    </androidx.cardview.widget.CardView>

</LinearLayout>

【讨论】:

    猜你喜欢
    • 2015-11-28
    • 2021-04-28
    • 2020-05-25
    • 2013-04-18
    • 1970-01-01
    • 2018-03-02
    • 1970-01-01
    • 1970-01-01
    • 2014-12-25
    相关资源
    最近更新 更多