我刚刚开始学习动画,我正在尝试在约束布局更改动画完成后添加另一个视图。我添加了一个监听器,用于约束布局发生变化的时间,但在动画开始时触发,而不是在动画完成后触发。
rootConstraintLayout.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
Log.d(TAG, "onLayoutChange: testing ");
}
});
Run Code Online (Sandbox Code Playgroud)
这是我用来更改布局的方法
private void changeExamplePageLayout() {
ConstraintSet constraintSetBeforeExample = new ConstraintSet();
ConstraintSet constraintSetAfterExample = new ConstraintSet();
constraintSetBeforeExample.clone(rootConstraintLayout);
constraintSetAfterExample.clone(getContext(), R.layout.example_fragment_sub_set);
TransitionManager.beginDelayedTransition(rootConstraintLayout);
constraintSetAfterExample.applyTo(rootConstraintLayout);
}
Run Code Online (Sandbox Code Playgroud)
任何指向我应该看的方向都将不胜感激。
我已经在几个地方看到了这一点,但由于没有在线示例,因此无法弄清楚如何实现它,我想知道我是否误解了它的含义。
addOnBackPressedCallback 的 android 开发者链接
我想知道这是否意味着我可以在我的片段中添加一个回调来onBackPressed()在它到达活动之前接收它。
在我的片段中,我实现了
implements OnBackPressedCallBack
Run Code Online (Sandbox Code Playgroud)
然后实现了方法
@Override
public boolean handleOnBackPressed() {
Log.d(TAG, "handleOnBackPressed: hello");
return true;
}
Run Code Online (Sandbox Code Playgroud)
但它没有拿起它并直接进入主要活动onBackPressed()。
我进一步阅读并看到我的片段需要从 FragmentActivity 扩展
public class MainExampleFragment extends FragmentActivity implements View.OnClickListener, OnBackPressedCallback {
Run Code Online (Sandbox Code Playgroud)
而不是
appCompatActivity.getSuppportFragmentManager
Run Code Online (Sandbox Code Playgroud)
打电话
FragmentActivity.getSupportFragmentManager
Run Code Online (Sandbox Code Playgroud)
相反,但是当尝试设置包时,这会在 Fragment.newInstance 方法中抛出并出错。
有没有人做这方面的信息,谢谢
此代码应该将单词的索引添加'hello'到indices数组中,但并未将它们添加到数组中:
words = %w(hello how are you then okay then hello how)
def global(arg1, arg2)
indices = []
arg1.each do |x, y|
indices << y if arg2 == x
end
indices
end
global(words,'hello')
#=> [nil, nil]
Run Code Online (Sandbox Code Playgroud)
我的代码有什么问题?