在recyclerview中,是否可以稍微从cardview中获取textview?

好的,这似乎是一个简单的问题,但是请相信我,我已经花费了数小时来完成此任务。只想知道是否有可能在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将放置在recyclerview中

windyleou 回答:在recyclerview中,是否可以稍微从cardview中获取textview?

尝试下面的代码,并在评论中更新我:

    fragmentManager = mainActivityContext.getSupportFragmentManager();
    fragmentTransaction = fragmentManager.beginTransaction();
    SurveyOverView surveyOverView = new SurveyOverView();
    Bundle bundle = new Bundle();
    bundle.putParcelable("SURVEY_QUESTION",surveys.get(position));
    surveyOverView.setArguments(bundle);      fragmentTransaction.replace(R.id.fragment_container,surveyOverView,FRAG_TAG);
    fragmentTransaction.addToBackStack(null);

    fragmentTransaction.commit();

如果您想将任何东西放在任何地方,请使用

  

framelayout

作为父母

,

有多种方法可以达到此效果。我可以通过将CardView封装在另一个ViewGroup中,然后将TextView(应该超出CardView的边界)来做到这一点。

一个这样的布局示例:

<?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>

temp_rounded_border.xml

<?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>

我尚未在Device上测试此代码,但这是设计视图在Android Studio中呈现的内容。

enter image description here

本文链接:https://www.f2er.com/3083353.html

大家都在问