相关疑难解决方法(0)

Android LinearLayout:在LinearLayout周围添加阴影边框

我想创建此LinearLayout的相同边框作为示例:

在此输入图像描述

在这个例子中,我们可以看到linearLayout周围的边界不一样.如何使用XML可绘制文件创建它?

现在,我只能在LinearLayout周围创建一个简单的边框,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
  <corners
      android:radius="1dp"
      android:topRightRadius="0dp"
      android:bottomRightRadius="0dp"
      android:bottomLeftRadius="0dp" />
  <stroke
      android:width="1dp"
      android:color="#E3E3E1" />

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

</shape>
Run Code Online (Sandbox Code Playgroud)

android border android-linearlayout

138
推荐指数
8
解决办法
24万
查看次数

只围绕cardview的顶角

我想只在卡片顶部转角.

我使用下面的属性,它正在四处转弯.

我想显示所有卡片的重叠

card_view:cardCornerRadius="4dp"
Run Code Online (Sandbox Code Playgroud)

这是我的布局

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/card_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    card_view:cardCornerRadius="4dp"
    card_view:cardPreventCornerOverlap="false"
    >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:id="@+id/re1">

        <TextView
            android:id="@+id/title"
            android:layout_width="match_parent"
            android:layout_height="20dp"
            android:background="@color/colorAccent"
            android:text="contact det"
            android:gravity="center_vertical"
            android:textColor="@android:color/white"
            android:textSize="14dp"/>

        <TextView
            android:id="@+id/txtName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Name"
            android:gravity="center_vertical"
            android:textSize="10dp"
            android:layout_below="@id/title"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="5dp"/>

        <TextView
            android:id="@+id/txtSurname"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Surname"
            android:gravity="center_vertical"
            android:textSize="10dp"
            android:layout_below="@id/txtName"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="5dp"
            />

        <TextView
            android:id="@+id/txtEmail"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Email"
            android:textSize="10dp"
            android:layout_marginTop="10dp"
            android:layout_alignParentRight="true"
            android:layout_marginRight="150dp"
            android:layout_alignBaseline="@id/txtName"/>

        <TextView
            android:id="@+id/txtAdd"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Address"
            android:textSize="10dp"
            android:layout_alignLeft="@id/txtEmail"
            android:layout_alignBaseline="@id/txtSurname"/>

    </RelativeLayout>


    </android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)

android android-layout android-cardview

36
推荐指数
5
解决办法
3万
查看次数

Cardview角落背景不透明

我有一个CardView支持小部件的自定义实现,但是当我将它包含在我的布局文件中时,我似乎无法获得角落的背景透明.但是,如果我只是将CardView支持小部件放在我的布局文件中,它就会突然运行.如何让我的自定义组件的角落透明?

例

这是我自定义CardView实现的布局文件:

view_card.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/view_card"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    style="@style/Custom.Widget.CardView">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="@dimen/default_padding">

    <TextView
        android:id="@+id/view_mainText"
        style="@style/Custom.Widget.TextView.Header"
        android:textColor="@color/instruction_balloon_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/view_subText"
        android:textSize="@dimen/text_size_medium"
        android:textColor="@color/instruction_balloon_text"
        android:singleLine="false"
        android:text="Please remove white corners :-("
        android:textIsSelectable="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

styles.xml

<style name="Custom.Widget.CardView" parent="CardView">
    <item name="cardBackgroundColor">@color/card_backgroundColor</item>
    <item name="cardCornerRadius">12dp</item>
</style>
Run Code Online (Sandbox Code Playgroud)

这是我的布局文件,包括两个CardViews.第一个带有白色角落,第二个带有与view_card.xml基本相同的布局但没有白色角落(透明).

的example.xml

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

    <some.private.namespace.CardView
        android:id="@+id/custom_card_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/default_margin" />

    <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/view_card"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/default_margin"
        style="@style/Custom.Widget.CardView">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:padding="@dimen/default_padding">

            <TextView
                android:id="@+id/view_mainText"
                style="@style/Custom.Widget.TextView.Header"
                android:textColor="@color/instruction_balloon_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView …
Run Code Online (Sandbox Code Playgroud)

android android-custom-view android-layout android-support-library android-cardview

10
推荐指数
2
解决办法
7791
查看次数

MaterialCardView 的不同角半径值

MaterialCardView 的每个角半径是否可以有不同的值?如果是这样怎么办?

我尝试了类似下面的代码,但似乎没有任何效果

    float radius = getContext().getResources().getDimension(R.dimen.default_corner_radius);
    ShapePathModel leftShapePathModel = new ShapePathModel();
    leftShapePathModel.setTopLeftCorner(new RoundedCornerTreatment(radius));
    leftShapePathModel.setTopRightCorner(new RoundedCornerTreatment(radius));
    MaterialShapeDrawable bg = new MaterialShapeDrawable(leftShapePathModel);
    container.setBackground(bg);
Run Code Online (Sandbox Code Playgroud)

容器在哪里

@BindView(R.id.container) MaterialCardView container;
Run Code Online (Sandbox Code Playgroud)

android android-layout android-cardview material-components material-components-android

10
推荐指数
3
解决办法
5273
查看次数

圆角cardView在RecyclerView中不起作用 - Android?

我的Android设备是4.3和不在角落的工作cardView:

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/tools"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/CardStart"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="5dp"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    android:scaleType="centerCrop"
    app:cardUseCompatPadding="true"
    card_view:cardBackgroundColor="@color/BlackTrans"
    card_view:cardCornerRadius="5dp"
    card_view:cardElevation="0dp">

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

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

            <TextView
                android:id="@+id/txtTitle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/txtDescription"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </LinearLayout>

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

            <ImageButton
                android:id="@+id/imgbIcon"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:src="@drawable/ic_serch" />
        </LinearLayout>
    </LinearLayout>
</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)

我在课堂上写了下面的代码,但还没有工作:

if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
{
    holder.CardStart.setCardElevation(0);
    holder.CardStart.setBackgroundColor(ContextCompat.getColor(context,R.color.BlackTrans));
    holder.CardStart.setRadius(5);
    holder.CardStart.setUseCompatPadding(true);
}
Run Code Online (Sandbox Code Playgroud)

android android-cardview android-recyclerview

9
推荐指数
2
解决办法
7326
查看次数

如何使用三个角和阴影制作图像视图

图片

如何制作只有三个角的图像,我尝试使用框架布局插入图像视图,并使其成为原始图像的资源,添加另一个具有 3 个角的边框 src 的图像视图,但它不起作用

xml android imageview material-components-android

5
推荐指数
1
解决办法
1754
查看次数

具有不同拐角半径的CardView

我有以下CardView,并且我想为卡中的每个角设置不同的半径。是否可以通过XML或以编程方式更改它们?提前致谢。

<android.support.v7.widget.CardView 
    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="wrap_content"
    android:layout_marginRight="16dp"
    android:layout_marginLeft="16dp"
    android:layout_marginTop="5dp"
    android:layout_marginBottom="5dp"
    app:cardCornerRadius="0dp"
    app:cardElevation="0dp">
</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)

编辑 正如阿维纳什(Avinash)所建议的那样,我正在寻找此lib github.com/captain-miao/OptionRoundCardview的行为,但使用默认的CardView项目。如果无法单独更改它,则此lib是一个不错的方法。

android android-layout material-design android-cardview material-components-android

4
推荐指数
1
解决办法
4400
查看次数

Cardview角落(边缘)显示为深色,如何解决?

我使用卡片视图作为自动滚动视图寻呼机的显示角,但卡片视图角显示颜色不同,请帮助我解决此问题

<android.support.v7.widget.CardView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
app:cardElevation="0dp"
app:cardCornerRadius="@dimen/_12sdp">
Run Code Online (Sandbox Code Playgroud)

看到这张图片

android android-viewpager android-cardview

3
推荐指数
1
解决办法
1344
查看次数