Coder Social home page Coder Social logo

googlearchive / android-constraintlayoutexamples Goto Github PK

View Code? Open in Web Editor NEW
2.6K 117.0 435.0 92.99 MB

Migrated:

Home Page: https://github.com/android/views-widgets-samples/tree/master/ConstraintLayoutExamples

License: Apache License 2.0

Java 73.12% Kotlin 26.88%

android-constraintlayoutexamples's Introduction

MotionLayout / Constraint Layout Samples

This sample has been migrated into the github.com/android/views-widgets repo. Please check that repo for future updates. Thank you!

android-constraintlayoutexamples's People

Contributors

camaelon avatar codingjeremy avatar edngulele avatar jafu888 avatar kaeawc avatar maxstalker avatar nageshs avatar naokigoogle avatar rayworks avatar saied89 avatar shazrazdan avatar thagikura avatar tomashavlicek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-constraintlayoutexamples's Issues

Caught an IllegalArgumentException due to the invalid container view id

The Steps to reproduce the crash

  1. Open the app
  2. Click the last item "Fragment Transition Example (2/2)"
  3. Drag the "MainFragment" square from bottom to top
  4. Click any item of the list

Attached log:

09-17 22:47:53.606 8844-8844/com.google.androidstudio.motionlayoutexample E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.google.androidstudio.motionlayoutexample, PID: 8844
    java.lang.IllegalArgumentException: No view found for id 0x7f0800b0 (com.google.androidstudio.motionlayoutexample:id/rv_item_placeholder) for fragment ItemFragment{dbf6a25 #6 id=0x7f0800b0}
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1422)
        at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1759)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1827)
        at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797)
        at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2596)
        at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2383)
        at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2338)
        at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:2215)
        at android.support.v4.app.BackStackRecord.commitNow(BackStackRecord.java:643)
        at com.google.androidstudio.motionlayoutexample.fragmentsdemo.CustomAdapter$onBindViewHolder$1.onClick(CustomAdapter.kt:44)
        at android.view.View.performClick(View.java:6305)
        at android.view.View$PerformClick.run(View.java:24840)
        at android.os.Handler.handleCallback(Handler.java:790)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6501)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

Visibility not applied.

Applying different Visibility in constraintsets it is not working. The view is always visible.

Try to run scene_19 with the position of the @id/fab somewhere visible since the beginning and you will notice that the button is always visible.

App crashes when clicking the item "CoordinatorLayout Example (3/3)"

E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.google.androidstudio.motionlayoutexample, PID: 13932
  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.google.androidstudio.motionlayoutexample/com.google.androidstudio.motionlayoutexample.DemoActivity}: java.lang.IllegalStateException: findViewById(R.id.motionLayout) must not be null
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
      at android.app.ActivityThread.-wrap11(Unknown Source:0)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
      at android.os.Handler.dispatchMessage(Handler.java:106)
      at android.os.Looper.loop(Looper.java:164)
      at android.app.ActivityThread.main(ActivityThread.java:6501)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
   Caused by: java.lang.IllegalStateException: findViewById(R.id.motionLayout) must not be null
      at com.google.androidstudio.motionlayoutexample.DemoActivity.onCreate(DemoActivity.kt:35)
      at android.app.Activity.performCreate(Activity.java:7036)
      at android.app.Activity.performCreate(Activity.java:7027)
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)

ViewPager with Tablayout and fragments behaves in wrong way inside motionlayout

I tried to replicate the same behavior of coordinator layout with MotionLayout and i got almost the same design but i faced some issues .

My design contains Motion Layout as a parent view and inside it it contains some child views and TabLayout , ViewPager included . everything works fine with a fresh start but when you try to swipe up the viewpager and then try to scroll viewpager fragment both direction you will see empty views although the fragment is created if i tried to push the viewpager down from top fragment starts displaying right away ! also the touch events are intercepted badly while dragging up then directly scroll between fragments

attached is my xml and motion scene
Main XML

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.motion.widget.MotionLayout 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"
    app:layoutDescription="@xml/collapsing_toolbar"
    tools:context=".MainActivity"
    tools:showPaths="true">

    <com.google.android.material.tabs.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/toolbar_image"
        app:tabBackground="@color/colorPrimary"
        app:tabGravity="fill"
        app:tabIndicatorColor="#ffffff"
        app:tabIndicatorHeight="4dp"
        app:tabMode="fixed">

    </com.google.android.material.tabs.TabLayout>

    <androidx.viewpager.widget.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/tabLayout">

    </androidx.viewpager.widget.ViewPager>

    <ImageView
        android:id="@+id/toolbar_image"
        android:layout_width="0dp"
        android:layout_height="200dp"
        android:adjustViewBounds="true"
        android:background="@color/colorPrimary"
        android:contentDescription="@null"
        android:fitsSystemWindows="true"
        android:scaleType="center"
        android:src="@drawable/beach_huts"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageView
        android:id="@android:id/home"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@null"
        android:paddingStart="16dp"
        android:paddingTop="16dp"
        android:paddingEnd="16dp"
        android:paddingBottom="16dp"
        android:src="@drawable/abc_ic_ab_back_material"
        android:tint="?android:attr/textColorPrimaryInverse"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:ignore="PrivateResource" />

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginBottom="24dp"
        android:text="@string/app_name"
        android:textColor="?android:attr/textColorPrimaryInverse"
        android:textSize="32sp"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="@id/toolbar_image"
        app:layout_constraintStart_toStartOf="parent" />

</androidx.constraintlayout.motion.widget.MotionLayout>

Motion Scene

<Transition
    app:constraintSetEnd="@id/collapsed"
    app:constraintSetStart="@id/expanded">
    <OnSwipe
        app:dragDirection="dragUp"
        app:touchAnchorId="@id/tabLayout"
        app:touchAnchorSide="top" />
</Transition>

<ConstraintSet android:id="@+id/expanded">
    <Constraint
        android:id="@id/toolbar_image"
        android:layout_height="200dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">
        <CustomAttribute
            app:attributeName="imageAlpha"
            app:customIntegerValue="255" />
    </Constraint>
    <Constraint
        android:id="@id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginBottom="24dp"
        android:scaleX="1.0"
        android:scaleY="1.0"
        app:layout_constraintBottom_toBottomOf="@id/toolbar_image"
        app:layout_constraintStart_toStartOf="parent" />
</ConstraintSet>

<ConstraintSet android:id="@+id/collapsed">
    <Constraint
        android:id="@id/toolbar_image"
        android:layout_height="?attr/actionBarSize"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">
        <CustomAttribute
            app:attributeName="imageAlpha"
            app:customIntegerValue="0" />
    </Constraint>
    <Constraint
        android:id="@id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="20dp"
        android:layout_marginBottom="0dp"
        android:scaleX="0.625"
        android:scaleY="0.625"
        app:layout_constraintBottom_toBottomOf="@id/toolbar_image"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@id/toolbar_image" />

</ConstraintSet>

The issue is fully reproducible

MotionLayout doesn't work if child view is clickable

I added ExoPlayer's PlayerView instead of ImageView to youtubedemo or changed ImageView(top_image) to clickable. And then MotionLayout swipe is not working.

Do you have any good idea without overriding any touch event methods?

Or how can I control MotionLayout precisely with overriding any touch event methods?

DrawerSample ClassCastException

When trying to check the samples on the DrawerLayout the app crashes with a ClassCastException:

09-13 15:13:09.244 4701-4701/com.google.androidstudio.motionlayoutexample E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.google.androidstudio.motionlayoutexample, PID: 4701
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.google.androidstudio.motionlayoutexample/com.google.androidstudio.motionlayoutexample.DemoActivity}: java.lang.ClassCastException: android.support.v4.widget.DrawerLayout cannot be cast to android.support.constraint.motion.MotionLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Caused by: java.lang.ClassCastException: android.support.v4.widget.DrawerLayout cannot be cast to android.support.constraint.motion.MotionLayout
at com.google.androidstudio.motionlayoutexample.DemoActivity.onCreate(DemoActivity.kt:35)
at android.app.Activity.performCreate(Activity.java:6662)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6077) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756) 

This is because the DemoActivity is trying to set to a MotionLayout element a android.support.v4.widget.DrawerLayout type given that for the Drawer sample that uses the motion_12_drawerlayout the root element with id motionLayout is actually a android.support.v4.widget.DrawerLayout

To reproduce it just open the app and try to enter the option DrawerLayoutExample (1/2) or DrawerLayoutExample (2/2)

Constraint Layout 2.0 Alpha 1 is not working with Navigation SafeArgs

Hi There,

I don't know if this is the appropriate place to report issues like that, but I could not find any other location.

It seems that something goes wrong with Navigation Safe Args when I add Constraint Layout 2.0 to my build.gradle.

My navigation arg looks like this:

 <argument
            android:name="aplicacaoId"
            app:type="integer" />

When I change the constraint layout to implementation 'com.android.support.constraint:constraint-layout:2.0.0-alpha1' Android Studio gives me the following error:

Output:  /nav_graph.xml:120: error: 'integer' is incompatible with attribute type (attr) enum [deltaRelative=0, parentRelative=2, pathRelative=1] [weak].

Thanks.

Constraint Layout Min SDK level

Currently constraint layout 2.0 alpha only supports a min sdk level of 18 in the support library. Is there any plans to back port it to earlier versions , like its predecessor (1.1.1) ?

When use a ScrollerView inside

I used a ScrollerView inside MotionLayout, and motionLayout won't respond to my actions when I try to swipe right. Please help me, Thinks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.