android - 删除 Android 顶部的 cardVie 的卡片背景

标签 android radio-button android-cardview

我想要得到这个结果。 Im trying to achieve this.但我得到的是 This这。下面是我尝试过的代码。我不知道我做错了什么。请帮忙。

    <FrameLayout
        android:id="@+id/bankToggle"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    <RadioGroup
        android:layout_width="match_parent"
        android:orientation="horizontal"
        android:layout_height="52dp">
        <android.support.v7.widget.CardView
            android:id="@+id/netbankingCard"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_marginBottom="-2dp"
            style="@style/carViewQuickInvestRadio"
            android:layout_marginRight="10dp"
            android:layout_height="match_parent">
        <RelativeLayout
            android:paddingTop="10dp"
            android:paddingBottom="10dp"
            android:id="@+id/netBankingrbrl"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <RelativeLayout
            android:id="@+id/relContainRadThisMonth"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <android.support.v7.widget.AppCompatRadioButton
                android:id="@+id/netbankingRB"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:checked="false"
                app:buttonTint="@color/color_green" />

            <com.goalwise.customViews.CustomTextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="10dp"
                android:textColor="@color/color_fab_text"
                android:layout_toRightOf="@+id/netbankingRB"
                android:text="@string/netbanking"
                android:textSize="@dimen/dashboard_regular_text_size"
                app:font="@string/gotham_font" />
        </RelativeLayout>
            <LinearLayout
                android:id="@+id/lnlContainRadThisMonth"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignBottom="@+id/relContainRadThisMonth"
                android:layout_alignLeft="@+id/relContainRadThisMonth"
                android:layout_alignRight="@+id/relContainRadThisMonth"
                android:layout_alignTop="@+id/relContainRadThisMonth"
                android:background="?android:selectableItemBackground"
                android:orientation="horizontal"></LinearLayout>

        </RelativeLayout>
        </android.support.v7.widget.CardView>
        <android.support.v7.widget.CardView
            android:id="@+id/nachrbcard"
            style="@style/carViewQuickInvestRadio"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_marginBottom="-2dp"
            android:layout_height="match_parent">
        <RelativeLayout
            android:paddingBottom="10dp"
            android:paddingTop="10dp"
            android:id="@+id/nachrbrl"
            android:layout_width="wrap_content"
            android:layout_height="match_parent">
        <RelativeLayout
            android:id="@+id/relContainRadNach"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <android.support.v7.widget.AppCompatRadioButton
                android:id="@+id/nachRB"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:checked="false"
                app:buttonTint="@color/color_green" />

            <com.goalwise.customViews.CustomTextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="10dp"
                android:textColor="@color/color_fab_text"
                android:layout_toRightOf="@+id/nachRB"
                android:text="@string/nach"
                android:textSize="@dimen/dashboard_regular_text_size"
                app:font="@string/gotham_font" />
        </RelativeLayout>
            <LinearLayout
                android:id="@+id/lnlContainRadNach"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignBottom="@+id/relContainRadNach"
                android:layout_alignLeft="@+id/relContainRadNach"
                android:layout_alignRight="@+id/relContainRadNach"
                android:layout_alignTop="@+id/relContainRadNach"
                android:background="?android:selectableItemBackground"
                android:orientation="horizontal"></LinearLayout>

        </RelativeLayout>
        </android.support.v7.widget.CardView>
    </RadioGroup>

        <FrameLayout
            android:id="@+id/frame_toggle"
            android:elevation="10dp"
            android:layout_marginTop="42dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            >
            <android.support.v7.widget.CardView
                android:id="@+id/cardNbNach"
                android:layout_marginTop="-1dp"
                style="@style/carViewQuickInvestRadio.bg"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <com.goalwise.customViews.CustomTextView
                    android:paddingBottom="15dp"
                    android:id="@+id/netBanking_both"
                    android:lineSpacingExtra="1.3dp"
                    android:paddingTop="12dp"
                    android:paddingLeft="15dp"
                    android:layout_gravity="top"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    style="@style/styleTextViewDisc"
                    android:text="@string/quick_net_both"
                    />
                <com.goalwise.customViews.CustomTextView
                    android:id="@+id/guarenteeTag"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="70dp"
                    android:text="@string/secure_transaction"
                    android:drawableLeft="@drawable/ic_lock"
                    android:gravity="center_horizontal"
                    android:drawablePadding="-20dp"
                    android:layout_gravity="bottom"
                    android:paddingTop="5dp"
                    android:paddingLeft="15dp"
                    android:paddingBottom="10dp"
                    style="@style/styleTextViewQuickDisc.noPadding"

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


    </FrameLayout>

上面的代码给了我显示的结果。我试图通过给予 -ve 边距来删除卡片 View 顶部的边框。这无助于解决问题。请帮忙。

最佳答案

This is how it looks!

你可以做这样的事情。这可能不是正确的方法。但它给出的结果几乎相同。

<?xml version="1.0" encoding="utf-8"?>

<android.support.v7.widget.CardView
    android:id="@+id/radioOne"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_weight="1"
    android:layout_toLeftOf="@+id/splitter"
    app:cardBackgroundColor="@color/color_white"
    app:cardCornerRadius="1dp"
    app:cardElevation="4dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginTop="50dp"
    />

<View
    android:id="@+id/splitter"
    android:layout_width="1px"
    android:layout_height="1px"
    android:layout_marginTop="50dp"
    android:layout_centerHorizontal="true"/>

<android.support.v7.widget.CardView
    android:id="@+id/radioTwo"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_toRightOf="@+id/splitter"
    android:layout_weight="1"
    app:cardBackgroundColor="#f7f7f7"
    app:cardElevation="0dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginTop="50dp"
    />
<android.support.v7.widget.CardView
    android:id="@+id/rootTwo"
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:layout_below="@+id/radioOne"
    app:cardBackgroundColor="@color/color_white"
    app:cardCornerRadius="1dp"
    app:cardElevation="4dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginBottom="8dp"
    />
<android.support.v7.widget.CardView
    android:id="@+id/patchView"
    android:layout_width="match_parent"
    android:layout_height="8dp"
    android:layout_below="@+id/radioOne"
    android:layout_toLeftOf="@+id/splitter"
    app:cardBackgroundColor="@color/color_white"
    app:cardCornerRadius="0dp"
    app:cardElevation="4dp"
    android:layout_marginTop="-4dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginBottom="8dp"
    />

确保您的所有卡片 View 都位于同一父 View 中,并且具有相同的高度。当您指定角半径时,阴影变得可见。为了隐藏那个阴影,我在上面应用了一个补丁。你可以清楚地看到我是如何在 xml 中做到这一点的。

谢谢。

关于android - 删除 Android 顶部的 cardVie 的卡片背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43585181/

相关文章:

java - picasso 图像未在 Gridview Android 中加载

java - OptionalPendingResult<GoogleSignInResult> 总是抛出 IllegalStateException,原因为 "Result has already been consumed"

java - eclipse for 循环分配按钮字符串

Jquery 未选中带有单选按钮的复选框

android - CardView 填充和圆角

java - android 编程 NameValuePair 为 api 23 删除

wpf - 在设置中存储单选按钮选择

php - 如何最好地使用 php 预填充单选按钮选择?

java - 在某些卡片 android 中,recyclerview 中的删除按钮位置不正确

android - 在弹出窗口中显示 RecyclerView