Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I think this is definitely a bug #838

Open
sunshaobei opened this issue Aug 4, 2023 · 6 comments
Open

I think this is definitely a bug #838

sunshaobei opened this issue Aug 4, 2023 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@sunshaobei
Copy link

layout : ViewPage2 or RecyclerView bind a itemView witch is ConstraintLayout with a child , and this child set paddingStart or paddingEnd,

first: I set the ConstraintLayout‘visibility Gone

second : when the view created i set ConstraintLayout‘visibility visible

then I found the child can not show

@sunshaobei sunshaobei added the bug Something isn't working label Aug 4, 2023
@sunshaobei
Copy link
Author

sunshaobei commented Aug 4, 2023

this is my code

 class MainActivity : AppCompatActivity() {
    val adapter = MyAdapter(this)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        findViewById<ViewPager2>(R.id.vp).adapter = adapter
    }
}

  class MyAdapter(activity: MainActivity) : FragmentStateAdapter(activity) {

    override fun getItemCount(): Int {
      return 1
    }

    override fun createFragment(position: Int): Fragment {
        return MainFragment()
    }
}

------------------------------------------------------- activity_main.layout

  <?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <androidx.viewpager2.widget.ViewPager2
        android:id="@+id/vp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>


/**
 * @author sunshaobei on 2023/8/4
 */
   class MainFragment:Fragment() {
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val dataBinding:FragmentMainBinding = DataBindingUtil.inflate(inflater,R.layout.fragment_main,container,false)
        dataBinding.testBtn.setOnClickListener {
            val value = dataBinding.tv.isLayoutRequested
            dataBinding.cl.isVisible = !dataBinding.cl.isVisible
        }
        return dataBinding.root
    }
}

------------------------------------------------------- fragment_main.layout

 <?xml version="1.0" encoding="utf-8"?>
 <layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <data>

    </data>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
 
        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/cl"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:visibility="gone"
            android:layout_gravity="center">

            <View
                android:id="@+id/tv"
                android:layout_width="60dp"
                android:layout_height="match_parent"
                android:background="#ff0000"
                android:gravity="center"
                android:paddingStart="6dp"
                android:textSize="13sp"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />


        </androidx.constraintlayout.widget.ConstraintLayout>


        <Button
            android:id="@+id/test_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="show"
            android:text="显示"
            android:layout_gravity="center_horizontal|bottom" />

    </FrameLayout>
</layout>

@sunshaobei
Copy link
Author

sunshaobei commented Aug 4, 2023

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <data>

    </data>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
       
        <LinearLayout
            android:id="@+id/cl"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:visibility="gone"
            android:layout_gravity="center">

            <View
                android:id="@+id/tv"
                android:layout_width="60dp"
                android:layout_height="match_parent"
                android:background="#ff0000"
                android:gravity="center"
                android:paddingStart="6dp"
                android:textSize="13sp"
            />

        </LinearLayout>


        <Button
            android:id="@+id/test_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="show"
            android:text="显示"
            android:layout_gravity="center_horizontal|bottom" />

    </FrameLayout>
</layout>

if i change the ContraintLayout to other viewgroup , that will be fine, or i delete the paddingStart of contraintlayout's child that will be fine too

@sunshaobei
Copy link
Author

or i just remove the viewpager2(recyclerview) that will be fine

@sunshaobei
Copy link
Author

i have no idear about this problem , and i have read a lot of source code of View、constraintlayout and recyclerview ,
then i found nothing

@sunshaobei
Copy link
Author

sunshaobei commented Aug 4, 2023

So, can you determine if this problem is ConstraintLayout‘s problem??? or recyclerview‘s

@sunshaobei
Copy link
Author

In this case , i found recyclerView+ConstraintString with RTL set like paddingStrat will be making this problem
,i fix this problem with a custom ConstraintLayout witch override it's addview(function) and add getPaddingStart() code only

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants