小编vla*_*lka的帖子

Android:GridLayout大小和View.GONE行为

GridLayout当其中一个孩子Visibility被设置为时GONE,我想做一个,它被下一个孩子取代. 在此输入图像描述

这不是我自己画的更好的解释.

我可以按照列数和宽度以及所有方式使布局工作.只是默认GONE行为GridLayout使得孩子只是消失而不是被替换,好像它不在那里,就像其他布局一样.

我确实尝试了很多东西,我尝试搜索SO和谷歌,但我似乎无法解决这个问题.这对于我正在处理的应用程序来说是最方便的布局.无论如何都要在布局中执行此操作而不必以编程方式执行此操作?或者两者的组合?

android android-gridlayout

11
推荐指数
3
解决办法
2046
查看次数

当触摸区域包含 RecyclerView 时,Android MotionLayout OnSwipe 不起作用

我正在尝试实现这个播放器动画

在此处输入图片说明

我还希望能够在折叠和展开时滑动歌曲。所以我们的想法是将 aMotionLayout与 a一起使用RecyclerView,并且还有RecyclerViewbe a 的每个项目MotionLayout。通过这种方式,我可以在 上应用展开动画,RecyclerView并在其子项上应用过渡。

如所附视频所示,过渡本身运行良好。但是让阻力作用于它RecyclerView本身并没有。仅当触摸从 外部开始时才会检测到拖动,RecyclerView如视频中突出显示的触摸所示,其中触摸从 下方开始RecyclerView

如果在 上开始触摸RecyclerView,则歌曲的滚动会消耗该事件。即使禁用附件LinearLayoutManager中的滚动也不起作用。我还尝试覆盖onTouchRecyclerView使其始终返回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

7
推荐指数
2
解决办法
2063
查看次数

定期向 Ratchet 中的客户端发送消息

我正在尝试定期发送“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)

php web-services websocket ratchet

4
推荐指数
1
解决办法
4150
查看次数

多个线程访问ArrayList

我有一个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索引在大小范围内,所以我想知道这是否可能导致问题或我应该寻找其他问题 .

谢谢

java multithreading arraylist

3
推荐指数
1
解决办法
5462
查看次数

在Kotlin中构建课程的正确方法是什么?

我有一个包含很多非空字段和可空字段的类.如果我宣布他们就好

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)

kotlin

0
推荐指数
1
解决办法
130
查看次数