我正在尝试实现这个播放器动画
我还希望能够在折叠和展开时滑动歌曲。所以我们的想法是将 aMotionLayout与 a一起使用RecyclerView,并且还有RecyclerViewbe a 的每个项目MotionLayout。通过这种方式,我可以在 上应用展开动画,RecyclerView并在其子项上应用过渡。
如所附视频所示,过渡本身运行良好。但是让阻力作用于它RecyclerView本身并没有。仅当触摸从 外部开始时才会检测到拖动,RecyclerView如视频中突出显示的触摸所示,其中触摸从 下方开始RecyclerView。
如果在 上开始触摸RecyclerView,则歌曲的滚动会消耗该事件。即使禁用附件LinearLayoutManager中的滚动也不起作用。我还尝试覆盖onTouch以RecyclerView使其始终返回false并且不消耗任何触摸事件(理论上),但这也不起作用。
该项目可以在这里找到https://github.com/vlatkozelka/PlayerAnimation2 它并不意味着成为一个生产就绪的应用程序,只是一个测试游乐场。
这是相关的代码
布局:
<?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"
android:background="@color/colorPrimary"
app:layoutDescription="@xml/player_scene"
tools:context=".MainActivity"
android:id="@+id/layout_main"
>
<FrameLayout
android:id="@+id/layout_player"
android:layout_width="match_parent"
android:layout_height="@dimen/mini_player_height"
android:elevation="2dp"
app:layout_constraintBottom_toTopOf="@id/layout_navigation"
app:layout_constraintStart_toStartOf="parent"
android:background="@color/dark_grey"
android:focusable="true"
android:clickable="true"
>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_songs"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="false"
android:clickable="false"
/>
</FrameLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/layout_navigation"
android:layout_width="match_parent" …Run Code Online (Sandbox Code Playgroud) android android-animation android-recyclerview android-motionlayout
我正在尝试定期发送“hello world!” 从 Ratchet 教程向连接到聊天服务器的所有客户端发送消息
我将在这里发布所有代码:Chat.php:
<?php
namespace MyApp;
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
class Chat implements MessageComponentInterface {
public $clients;
public function __construct() {
$this->clients = new \SplObjectStorage;
}
public function onOpen(ConnectionInterface $conn) {
// Store the new connection to send messages to later
$this->clients->attach($conn);
echo "New connection! ({$conn->resourceId})\n";
}
//this worked but I don't want this behaviour
public function onMessage(ConnectionInterface $from, $msg) {
/*$numRecv = count($this->clients) - 1;
echo sprintf('Connection %d sending message "%s" to %d other connection%s' . …Run Code Online (Sandbox Code Playgroud) 我有一个ArrayList,用于缓冲数据,以便其他线程可以读取它们
这个数组不断添加数据,因为它从udp源读取,而其他线程不断从该数组读取.然后从数组中删除数据.
这不是实际的代码,而是一个简化的例子:
public class PacketReader implements Runnable{
pubic static ArrayList<Packet> buffer = new ArrayList() ;
@Override
public void run(){
while(bActive){
//read from udp source and add data to the array
}
}
public class Player implements Runnable(){
@Override
public void run(){
//read packet from buffer
//decode packets
// now for the problem :
PacketReader.buffer.remove(the packet that's been read);
}
}
Run Code Online (Sandbox Code Playgroud)
remove()方法从数组中删除数据包,然后将右侧的所有数据包移到左侧以覆盖空白.
我担心的是:由于缓冲区经常被多个线程添加和读取,因此remove()方法会产生问题,因为它必须将数据包移到左边?
我的意思是如果.add()或.get()方法在该arraylist上被调用,同时正在进行转换会是一个问题吗?
我有时会得到索引超出范围的异常,它的类似于:index:100 size 300,这是奇怪的cuz索引在大小范围内,所以我想知道这是否可能导致问题或我应该寻找其他问题 .
谢谢
我有一个包含很多非空字段和可空字段的类.如果我宣布他们就好
val key : String
Run Code Online (Sandbox Code Playgroud)
在科特林编译器会当然给我一个错误,告诉我,他们需要被初始化,所以我想我应该把不能为空那些在构造函数中,并添加辅助构造,当我需要与非空值初始化为空的字段.这是为了避免调用构造函数然后调用setter,然后我会调用一个构造函数.这就是它看起来像
import utilities.Constants
import java.util.*
class Action(val key: String,
//val actionNode: ActionNode
val date: Date,
val stringValue: String,
val autoRecognitionStatus: Constants.MeasurementAutoRecognized,
val recognitionId: String,
val method: Constants.MeasurementMethod,
val userKey: String,
val userName: String,
val isInRange: Boolean) {
var pictureUrl: String? = null
var remotePictureUrl: String? = null
constructor(key: String,
// actionNode: ActionNode
date: Date,
stringValue: String,
autoRecognitionStatus: Constants.MeasurementAutoRecognized,
recognitionId: String,
method: Constants.MeasurementMethod,
userKey: String,
userName: String,
isInRange: Boolean,
pictureUrl: String?,
remotePictureUrl: String?)
: this(key,
// …Run Code Online (Sandbox Code Playgroud)