Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Imageview不采用cardview的角半径_Java_Android_Xml_User Interface - Fatal编程技术网

Java Imageview不采用cardview的角半径

Java Imageview不采用cardview的角半径,java,android,xml,user-interface,Java,Android,Xml,User Interface,大家好,我正在开发一个应用程序,其中我在cardview内部使用imageview,但我的问题是imageview没有采用应用于cardview的角半径 请看下图 我试着做不同的事情,但不明白问题出在哪里。如果有人能给我指导的话 我的xml 试试这个方法: <?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.CardView xmlns:android="http://schemas.

大家好,我正在开发一个应用程序,其中我在cardview内部使用imageview,但我的问题是imageview没有采用应用于cardview的角半径 请看下图 我试着做不同的事情,但不明白问题出在哪里。如果有人能给我指导的话 我的xml


试试这个方法:

  <?xml version="1.0" encoding="utf-8"?>
  <android.support.v7.widget.CardView
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:cardview="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:padding="@dimen/_5sdp"
  android:layout_marginTop="@dimen/_5sdp"
  android:layout_marginLeft="@dimen/_5sdp"
  android:layout_marginRight="@dimen/_5sdp"
  android:layout_marginBottom="5dp"
  cardview:cardCornerRadius="@dimen/_3sdp"
  cardview:cardElevation="@dimen/_3sdp"
  cardview:cardUseCompatPadding="true">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/thumbnail"
        android:layout_width="match_parent"
        android:layout_height="@dimen/_180sdp"
        android:layout_alignParentTop="true"
        android:scaleType="centerCrop"
        android:src="@drawable/placeholder"/>



    <RelativeLayout
        android:padding="@dimen/_5sdp"
        android:id="@+id/rlMiddle"
        android:layout_below="@+id/thumbnail"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


        <TextView
            android:id="@+id/txtPrescription"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/_10sdp"
            android:maxLines="3"
            android:paddingTop="8dp"
            android:textAppearance="@style/TextAppearance.AppCompat.Headline"
            android:textSize="@dimen/_16sdp"
            android:text="Demo"
            android:textStyle="bold"
           />
      </RelativeLayout>
    </RelativeLayout>
 </android.support.v7.widget.CardView>

您可以使用
RoundedImageView

把这个放进去,格雷德尔

编译'com.makeramen:roundedimageview:2.3.0'

使用它:

<com.makeramen.roundedimageview.RoundedImageView
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:background="@android:color/transparent"
    android:scaleType="centerCrop"
    app:riv_corner_radius="5dp"/>

见下图。请记住,不要将
cardwiew
作为主布局



只需在xml中使用此代码,并在运行代码后查看结果:

<android.support.v7.widget.CardView
    android:layout_marginTop="100dp"
    android:layout_gravity="center_horizontal"
    app:cardCornerRadius="20dp"
    android:id="@+id/cv"
    android:clipChildren="true"
    android:layout_width="100dp"
    android:layout_height="wrap_content">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <ImageView
        android:scaleType="centerCrop"
        android:src="@drawable/recipe"
        android:layout_width="match_parent"
        android:layout_height="100dp" />

        <TextView
            android:layout_margin="8dp"
            android:text="ITEM"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:layout_marginLeft="8dp"
            android:layout_marginBottom="8dp"
            android:text="34"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </LinearLayout>
</android.support.v7.widget.CardView>

尝试用相对布局替换线性布局。
之后,设置上一个文本视图的重心(水平居中)。

您是否尝试将图像设置为CardViewyes@Meline的背景?我尝试将其设置为cardview的背景以及使用自定义背景或使用边距。将填充设置为父视图可能有助于卡视图的自定义背景@Jyoti JKUse
app:contentPadding=“10dp”
是什么意思。让
ViewGroup的
as
wrap\u content
。Hi@jeet parmar尝试了您的答案,但仍然没有获得ImageView的圆角半径。您可以发送您的新xml吗?如果有任何问题,您可以回收视图布局吗?。Hi@jeet parmar您可以帮我解决这个问题吗?Hi@jeet parmar谢谢您的回复,但我最终使用了自定义imageview as@Nilesh suggestedhi-Deven你能帮我吗
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_margin="1dp"
    android:orientation="vertical">

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    app:cardUseCompatPadding="true"
    android:elevation="0dp"
    app:cardCornerRadius="5dp"
    android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">


        <ImageView
            android:id="@+id/iv_suvichar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/placeholder" />

        <TextView
            android:id="@+id/tv_suvichar_title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Title"
            android:padding="5dp"
            android:textColor="@color/black"
            android:textSize="@dimen/normal_text_size" />

    </LinearLayout>

</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
    android:layout_marginTop="100dp"
    android:layout_gravity="center_horizontal"
    app:cardCornerRadius="20dp"
    android:id="@+id/cv"
    android:clipChildren="true"
    android:layout_width="100dp"
    android:layout_height="wrap_content">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <ImageView
        android:scaleType="centerCrop"
        android:src="@drawable/recipe"
        android:layout_width="match_parent"
        android:layout_height="100dp" />

        <TextView
            android:layout_margin="8dp"
            android:text="ITEM"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:layout_marginLeft="8dp"
            android:layout_marginBottom="8dp"
            android:text="34"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </LinearLayout>
</android.support.v7.widget.CardView>