Android 在recyclerview中是否可能有一个稍微超出cardview的文本视图?
好吧,这似乎是一个简单的问题,但相信我,我已经花了几个小时来完成这项工作。只是想知道是否有可能在cardView的右侧稍微显示一个textview。顺便说一句,texview有很多布局,如线性布局和相对布局 我还尝试在其父布局的xml中添加此代码android:clipToPadding=“false”和android:clipChildren=“false”仍然不起作用。我不知道为什么它对我不起作用。我已经附上了我希望textview的布局的图片。我应该在我的recyclerview的适配器中添加一些代码吗?请帮忙。提前谢谢Android 在recyclerview中是否可能有一个稍微超出cardview的文本视图?,android,android-recyclerview,android-linearlayout,android-cardview,android-relativelayout,Android,Android Recyclerview,Android Linearlayout,Android Cardview,Android Relativelayout,好吧,这似乎是一个简单的问题,但相信我,我已经花了几个小时来完成这项工作。只是想知道是否有可能在cardView的右侧稍微显示一个textview。顺便说一句,texview有很多布局,如线性布局和相对布局 我还尝试在其父布局的xml中添加此代码android:clipToPadding=“false”和android:clipChildren=“false”仍然不起作用。我不知道为什么它对我不起作用。我已经附上了我希望textview的布局的图片。我应该在我的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将被放置在回收视图中请尝试下面的代码并在注释中更新我:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:clipChildren="false"
android:clipToPadding="false"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<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"/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<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_marginTop="what ever of your card view"
android:layout_width="wrap_content"
android:text="this_is_the_textview_i_want_it_to_come_out_slightly"
android:layout_height="wrap_content"/>
</FrameLayout>
如果你想把任何东西放在任何地方,请使用
框架布局
作为家长有多种方法可以达到这种效果。我会将
cardwiew
封装在另一个ViewGroup
中,然后放入TextView
(应该超出cardwiew
的范围)
此类布局的一个示例:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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="match_parent"
>
<androidx.cardview.widget.CardView
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_margin="20dp"
android:foreground="#ACDBDA"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</androidx.cardview.widget.CardView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="20% Off"
android:textColor="#000000"
android:textSize="18sp"
android:textStyle="bold"
android:layout_marginBottom="10dp"
android:layout_marginEnd="10dp"
android:padding="7dp"
android:elevation="5dp"
android:background="@drawable/temp_rounded_border"
app:layout_constraintBottom_toBottomOf="@id/cardView"
app:layout_constraintEnd_toEndOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
将代码复制为文本pls@alirezadaryani我已经添加了xml的代码。请帮忙。谢谢如果我像你那样放置文本视图,我将无法实现我想要的视图。你看到我添加的图像了吗?我想实现的视图?我在代码之前添加了图像链接。嗨@rana,欢迎来到StackOverflow,如果你发现答案有帮助,请投票,因为答案解决了你的问题,我建议你将答案标记为正确/被接受,这样当其他人找到这篇文章时,他们就知道哪个答案最有可能解决他们的问题。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#8080FF" />
<corners
android:radius="5dp"
android:topRightRadius="0dp"
android:bottomRightRadius="0dp"
/>
<stroke android:color="#8080FF" android:width="1dp" />
</shape>