1. 程式人生 > 其它 >手機直播原始碼,實現簡單的聊天列表

手機直播原始碼,實現簡單的聊天列表

手機直播原始碼,實現簡單的聊天列表

@Composable
fun MessageCard(msg: Message) {
Row(modifier = Modifier.padding(all = 8.dp)) {
//設定圖片
Image(
painter = painterResource(R.drawable.img),
contentDescription = null,
modifier = Modifier
.size(40.dp)
.clip(CircleShape)
.border(1.5.dp, MaterialTheme.colors.secondaryVariant, CircleShape)
)

設定間距

Spacer(modifier = Modifier.width(8.dp))
    // We keep track if the message is expanded or not in this
    // variable 訊息是否展開的動畫
    var isExpanded by remember { mutableStateOf(false) }
    // We toggle the isExpanded variable when we click on this Column
    Column(modifier = Modifier.clickable { isExpanded = !isExpanded }) {
        //設定文字屬性
        Text(
            text = msg.author,
            color = MaterialTheme.colors.secondaryVariant,
            style = MaterialTheme.typography.subtitle2
        )
        Spacer(modifier = Modifier.height(4.dp))
        Surface(
            shape = MaterialTheme.shapes.medium,
            elevation = 1.dp,
        ) {
            Text(
                text = msg.body,
                modifier = Modifier.padding(all = 4.dp),
                // If the message is expanded, we display all its content
                // otherwise we only display the first line
                maxLines = if (isExpanded) Int.MAX_VALUE else 1,
                style = MaterialTheme.typography.body2
            )
        }
    }
}
    // We keep track if the message is expanded or not in this
    // variable 訊息是否展開的動畫
    var isExpanded by remember { mutableStateOf(false) }
    // We toggle the isExpanded variable when we click on this Column
    Column(modifier = Modifier.clickable { isExpanded = !isExpanded }) {
        //設定文字屬性
        Text(
            text = msg.author,
            color = MaterialTheme.colors.secondaryVariant,
            style = MaterialTheme.typography.subtitle2
        )
        Spacer(modifier = Modifier.height(4.dp))
        Surface(
            shape = MaterialTheme.shapes.medium,
            elevation = 1.dp,
        ) {
            Text(
                text = msg.body,
                modifier = Modifier.padding(all = 4.dp),
                // If the message is expanded, we display all its content
                // otherwise we only display the first line
                maxLines = if (isExpanded) Int.MAX_VALUE else 1,
                style = MaterialTheme.typography.body2
            )
        }
    }
}

以上就是手機直播原始碼,實現簡單的聊天列表, 更多內容歡迎關注之後的文章