小编Poy*_*nan的帖子

如何设置数据绑定中包含布局的可见性?

我已经在我的项目中实现了数据绑定。我有一个特定的屏幕,在 include 标签中有两个嵌套布局。我无法以编程方式使用数据绑定更改包含布局的可见性。

但是,我已经通过布尔值实现了它,但我的问题是如何以编程方式设置包含标记的可见性。

我的xml:

<include
  android:id="@+id/reg_email"
  layout="@layout/custom_email"
  android:layout_width="match_parent"
  android:layout_height="match_parent"/>


<include
  android:id="@+id/reg_phone"
  layout="@layout/custom_phone"
  android:layout_width="match_parent"
  android:layout_height="match_parent"/>
Run Code Online (Sandbox Code Playgroud)

在活动中:当我尝试设置它时 - 它变成红色,这意味着它不会将其视为视图。

  dataBinding.regPhone.setVisibility(View.GONE);
  dataBinding.regEmail.setVisibility(View.VISIBLE);
Run Code Online (Sandbox Code Playgroud)

java android android-databinding android-jetpack

8
推荐指数
1
解决办法
3195
查看次数

MotionLayout:单击和触摸在运动场景中的过渡时不起作用(像 UI 一样的 Youtube 播放器)

我有一个类似视图的 Youtube 视频播放器,我有一个列表,点击后会在下一个屏幕中播放视频。

我已将 Motionscene 添加到视频视图中,因此在向下拖动时,视频视图变小。但是这样做时 onClick 或 onTouch 事件不适用于播放/暂停控件。

在 youtube 上,我们可以看到两者都运行良好。所以我想知道我哪里出错了。

运动场景:

<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:motion="http://schemas.android.com/apk/res-auto">

    <Transition
        motion:constraintSetEnd="@id/collapsed"
        motion:constraintSetStart="@id/expanded"
        motion:duration="100">

        <OnSwipe
            motion:dragDirection="dragDown"
            motion:maxAcceleration="200"
            motion:touchAnchorId="@+id/player"
            motion:touchAnchorSide="bottom" />

    </Transition>

    <ConstraintSet android:id="@+id/expanded">

        <Constraint
            android:id="@id/player"
            android:layout_height="200dp"
            motion:layout_constraintEnd_toEndOf="parent"
            motion:layout_constraintStart_toStartOf="parent"
            motion:layout_constraintTop_toTopOf="parent" />

        <Constraint
            android:id="@id/scrollView"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:visibility="visible"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintTop_toBottomOf="@id/player" />

    </ConstraintSet>

    <ConstraintSet android:id="@+id/collapsed">

        <Constraint
            android:id="@id/player"
            android:layout_height="85dp"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintEnd_toEndOf="parent"
            motion:layout_constraintStart_toStartOf="parent" />

        <Constraint
            android:id="@id/scrollView"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:visibility="gone"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintTop_toBottomOf="@id/player" />

    </ConstraintSet>
</MotionScene>
Run Code Online (Sandbox Code Playgroud)

主布局:

<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/youtube_scene"
    tools:context=".ProfileActivity"
    tools:showPaths="true">


    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/player"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        app:layout_constraintBottom_toTopOf="@id/scrollView" …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-constraintlayout android-motionlayout

6
推荐指数
1
解决办法
1123
查看次数