是否可以将 textview 稍微移出其 cardView?
Is it possible to move a textview slightly out of its cardView?
好吧,这似乎是一个简单的问题,但相信我,我已经花了几个小时来完成这个问题。只是想知道是否可以在 cardView 的右侧稍微带出一个 textview。顺便说一句,texview 在许多布局下,例如线性布局和相对布局。
我也尝试在其父布局的 xml 中添加此代码。 android:clipToPadding="false" 和 android:clipChildren="false" 并且它仍然不工作。我不确定为什么它对我不起作用。我附上了我希望 textview 的布局看起来如何的图像 like.Should 我在我的 recyclerview 的适配器中添加了一些代码?请帮忙。提前致谢
<android.support.v7.widget.CardView xmlns:tools="http://schemas.android.com/tools"
xmlns:card_View="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:clipChildren="false"
android:clipToPadding="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_View:cardUseCompatPadding="false">
<LinearLayout
android:id="@+id/random"
android:clipChildren="false"
android:clipToPadding="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/random2"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<LinearLayout
android:id="@+id/random3"
android:clipChildren="false"
android:clipToPadding="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/random4"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<View
android:id="@+id/random5"
android:layout_width="0dp"
android:layout_height="0dp"/>
<TextView
android:id="@+id/this_is_the_textview_i_want_it_to_come_out_slightly"
android:layout_marginEnd="-5dp"
android:layout_marginRight="-5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
下面附上的代码在cardView中,cardView将被放置在recycverview中
您可以使用 RelativeLayout
和 elevation
来实现您的目标。
您需要调整 TextView
的高度,使其高于 CardView
。
你试试这样吧
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_View="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp">
<androidx.cardview.widget.CardView
android:id="@+id/card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_View:cardCornerRadius="6dp"
card_View:cardUseCompatPadding="true">
<LinearLayout
android:id="@+id/random"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:orientation="vertical">
<TextView
android:id="@+id/random2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="12dp"
android:text="kjabsfd"
android:textSize="16dp"
android:textStyle="bold" />
<LinearLayout
android:id="@+id/random3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipChildren="false"
android:clipToPadding="false"
android:orientation="vertical"
android:paddingStart="12dp"
android:paddingBottom="12dp">
<TextView
android:id="@+id/random4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:text="khfsda"
android:textSize="16dp" />
<View
android:id="@+id/random5"
android:layout_width="0dp"
android:layout_height="0dp" />
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
<TextView
android:id="@+id/this_is_the_textview_i_want_it_to_come_out_slightly"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:background="@color/colorAccent"
android:text="100% OFF"
android:textSize="16dp"
android:elevation="4dp"
android:layout_alignBottom="@id/card"
android:layout_marginBottom="12dp"/>
</RelativeLayout>
好吧,这似乎是一个简单的问题,但相信我,我已经花了几个小时来完成这个问题。只是想知道是否可以在 cardView 的右侧稍微带出一个 textview。顺便说一句,texview 在许多布局下,例如线性布局和相对布局。
我也尝试在其父布局的 xml 中添加此代码。 android:clipToPadding="false" 和 android:clipChildren="false" 并且它仍然不工作。我不确定为什么它对我不起作用。我附上了我希望 textview 的布局看起来如何的图像 like.Should 我在我的 recyclerview 的适配器中添加了一些代码?请帮忙。提前致谢
<android.support.v7.widget.CardView xmlns:tools="http://schemas.android.com/tools"
xmlns:card_View="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:clipChildren="false"
android:clipToPadding="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_View:cardUseCompatPadding="false">
<LinearLayout
android:id="@+id/random"
android:clipChildren="false"
android:clipToPadding="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/random2"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<LinearLayout
android:id="@+id/random3"
android:clipChildren="false"
android:clipToPadding="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/random4"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<View
android:id="@+id/random5"
android:layout_width="0dp"
android:layout_height="0dp"/>
<TextView
android:id="@+id/this_is_the_textview_i_want_it_to_come_out_slightly"
android:layout_marginEnd="-5dp"
android:layout_marginRight="-5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
下面附上的代码在cardView中,cardView将被放置在recycverview中
您可以使用 RelativeLayout
和 elevation
来实现您的目标。
您需要调整 TextView
的高度,使其高于 CardView
。
你试试这样吧
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_View="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp">
<androidx.cardview.widget.CardView
android:id="@+id/card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_View:cardCornerRadius="6dp"
card_View:cardUseCompatPadding="true">
<LinearLayout
android:id="@+id/random"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:orientation="vertical">
<TextView
android:id="@+id/random2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="12dp"
android:text="kjabsfd"
android:textSize="16dp"
android:textStyle="bold" />
<LinearLayout
android:id="@+id/random3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipChildren="false"
android:clipToPadding="false"
android:orientation="vertical"
android:paddingStart="12dp"
android:paddingBottom="12dp">
<TextView
android:id="@+id/random4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:text="khfsda"
android:textSize="16dp" />
<View
android:id="@+id/random5"
android:layout_width="0dp"
android:layout_height="0dp" />
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
<TextView
android:id="@+id/this_is_the_textview_i_want_it_to_come_out_slightly"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:background="@color/colorAccent"
android:text="100% OFF"
android:textSize="16dp"
android:elevation="4dp"
android:layout_alignBottom="@id/card"
android:layout_marginBottom="12dp"/>
</RelativeLayout>