android - 以编程方式运动布局
问题描述
这是我在这个平台上的第一个问题,我正在制作应用程序的一部分,我需要使用运动布局动态移动文本视图,但是当我showBubble ()
在执行应用程序时添加我的方法时不显示文本视图,有一些东西我想?我认为在检测 BubbleUi 的 id 时 XML 中存在一些错误,但归根结底,它可能比看起来更容易,你知道 :(
注:我正在翻译这篇文章,如果写作有任何错误,请见谅
XML:
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:motion="http://schemas.android.com/apk/res-auto">
<Transition
motion:constraintSetEnd="@id/end"
motion:constraintSetStart="@+id/start"
motion:duration="3500"
>
<OnClick
motion:targetId="@+id/Bubble"
motion:clickAction="toggle"
/>
</Transition>
<ConstraintSet android:id="@+id/start">
<Constraint
android:id="@id/Bubble"
android:layout_width="70dp"
android:layout_height="70dp"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
>
<CustomAttribute
motion:attributeName="backgroundColor"
motion:customColorValue="@color/colorGreenLight"
/>
</Constraint>
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@+id/Bubble"
android:layout_width="100dp"
android:layout_height="100dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
>
<CustomAttribute
motion:attributeName="backgroundColor"
motion:customColorValue="@color/colorGreenLight"
/>
</Constraint>
</ConstraintSet>
</MotionScene>
爪哇:
private void ShowBubble(String tempWord) {
//Create Motion layout.
MotionLayout motionBubble = new MotionLayout(ActivityGame.this);
motionBubble.setId(View.generateViewId());
motionBubble.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
LinearLayout.LayoutParams linearParams= new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT);
linearParams.setMargins(5,0,5,0);
motionBubble.setLayoutParams(linearParams);
//Create the Bubble.
TextView BubbleUi = new TextView(ActivityGame.this);
BubbleUi.setId(R.id.Bubble);
BubbleUi.setText(tempWord);
BubbleUi.setTextSize(24);
BubbleUi.setTextColor(getResources().getColor(R.color.colorDefaultWhite));
BubbleUi.setBackgroundColor(getResources().getColor(R.color.colorGreenLight));
BubbleUi.setLayoutParams(new ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.WRAP_CONTENT, ConstraintLayout.LayoutParams.WRAP_CONTENT));
BubbleUi.setGravity(Gravity.CENTER);
motionBubble.addView(BubbleUi,0);
ConstraintSet constraintSetBubble = new ConstraintSet();
constraintSetBubble.clone(motionBubble);
constraintSetBubble.connect(BubbleUi.getId(),ConstraintSet.TOP,ConstraintSet.PARENT_ID,ConstraintSet.TOP);
constraintSetBubble.connect(BubbleUi.getId(),ConstraintSet.START,ConstraintSet.PARENT_ID,ConstraintSet.START);
constraintSetBubble.connect(BubbleUi.getId(),ConstraintSet.END,ConstraintSet.PARENT_ID,ConstraintSet.END);
constraintSetBubble.applyTo(motionBubble);
//set transition.
motionBubble.loadLayoutDescription(R.xml.scene_bubbles);
linearLayoutBubbles.addView(motionBubble,indiceBubble);
CurrentMotionBubbleCycle [indiceBubble] = motionBubble;
motionBubble.transitionToStart();
motionBubble.transitionToEnd();
}
解决方案
推荐阅读
- shell - 错误:本地不存在应用程序版本。将战争工件上传到 aws beanstalk 环境时出错
- node.js - Express/Node 依赖模式:我可以为“app”实例使用单独的服务文件吗?
- hyperledger-fabric - 超级账本结构链码签名和安装如何工作?
- php - 当 html 代码作为电子邮件发送时,事情无法正常工作
- amazon-ec2 - 将 PHP 版本 5.3 更新到 7.2 Amazon aws ec2
- python - 找到叶子的周长
- r - 在R中转换为循环
- python - 如何在python中使用字典作为密码数据库
- python - 按 Pandas 中的第二项对元组系列进行排序
- python - Tweepy人员搜索和从python中搜索返回的人员列表