删除顶级Android上的cardVie卡背景

时间:2017-04-24 10:03:03

标签: 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 margin去除卡片视图顶部的边框。这没有帮助解决问题。请帮忙。

2 个答案:

答案 0 :(得分:2)

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"
    />

确保所有卡片视图位于同一个父级,并且具有相同的高程。给角半径时阴影变得可见。所以要隐藏那个影子,我正在应用补丁。您可以清楚地看到我是如何在xml中完成的。

谢谢。

答案 1 :(得分:0)

<android.support.v7.widget.CardView
    android:id="@+id/cardNbNach"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <LinearLayout
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:orientation="vertical">
        <LinearLayout
            android:paddingTop="10dp"
            android:layout_width="wrap_content"
            android:paddingBottom="10dp"
            android:id="@+id/relContainRadThisMonth"
           android:orientation="horizontal"
            android:layout_height="wrap_content">

            <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/grey" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="10dp"
                android:textColor="#000000"
                android:layout_toRightOf="@+id/netbankingRB"
                android:text="Net Banking"
                android:textSize="18sp"
                />
        </LinearLayout>
                <View
                    android:id="@+id/netbanking_bottomline"
                    android:layout_width="match_parent"
                    android:layout_height="2dp"
                    android:background="@color/grey"
                   />
            </LinearLayout>
            <View
                android:layout_width="2dp"
                android:layout_height="match_parent"
                android:background="@color/grey"
                android:layout_marginRight="5dp"/>
            <View
                android:layout_width="2dp"
                android:layout_height="match_parent"
                android:background="@color/grey"
                android:layout_marginLeft="5dp"/>
            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="vertical">
        <LinearLayout
            android:paddingBottom="10dp"
            android:paddingTop="10dp"
            android:id="@+id/relContainRadNach"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <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/grey" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="10dp"
                android:textColor="#000000"
                android:layout_toRightOf="@+id/nachRB"
                android:text="NACH"
                android:textSize="18sp"
                />
        </LinearLayout>
                <View
                    android:id="@+id/nach_bottom_line"
                    android:layout_width="match_parent"
                    android:layout_height="2dp"
                    android:background="@color/grey"
                    />
            </LinearLayout>
        </LinearLayout>
    <TextView
        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"
        android:text="test"
        />
    <TextView
        android:id="@+id/guarenteeTag"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="70dp"
        android:text="test"
        android:gravity="center_horizontal"
        android:drawablePadding="-20dp"
        android:layout_gravity="bottom"
        android:paddingTop="5dp"
        android:paddingLeft="15dp"
        android:paddingBottom="10dp"


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

你可以简单地使用单卡,当你点击NetBanking时,你需要消除视图的可见性(netbanking_bottomline),当你点击NACH时,你需要离开视图(nach_bottom_line)。

这可能是隐藏点击项目底线的简单步骤,而不是为卡片设置负边距。