RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-589857

A1pha's questions

Martin Hope
A1pha
Asked: 2025-01-18 02:10:23 +0000 UTC

自定义视图不调整宽度

  • 5

我有三个自定义视图:SmallBannerView、LargeBannerView 以及作为前两个视图基础的 BannerView。分别,前两个视图按其应有的方式显示,但是当我将它们附加到 BannerView 时,一切都崩溃了:由于某种原因,它们开始向左边框“收缩”,并且尝试增加宽度没有任何效果,仅包围视图的框架增加。

SmallBannerView 标记:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="88dp"
    android:layout_height="88dp"
    android:id="@+id/small_banner_view"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="@drawable/small_banner_card">
    
    <ImageView
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        android:layout_margin="4dp"
        android:id="@+id/image"
        android:layout_width="35dp"
        android:layout_height="35dp"
        tools:src="@drawable/bonus_badge"/>
    
    <TextView
        android:id="@+id/right_title"
        android:layout_marginTop="4dp"
        android:layout_marginHorizontal="6dp"
        app:layout_constraintTop_toBottomOf="@id/image"
        android:layout_width="match_parent"
        android:layout_height="14dp"
        android:textColor="@color/black"
        tools:text="Акции"
        android:textSize="12sp"
        android:fontFamily="sans-serif-medium"
        android:gravity="end"
        android:includeFontPadding="false"
        android:maxLines="1"
        android:ellipsize="end"/>

    <TextView
        android:id="@+id/left_title"
        android:layout_marginTop="6dp"
        android:layout_marginHorizontal="10dp"
        app:layout_constraintTop_toBottomOf="@id/right_title"
        android:textStyle="bold"
        android:layout_width="match_parent"
        android:layout_height="20dp"
        android:textColor="@color/black"
        tools:text="2 в 1"
        android:textSize="16sp"
        android:fontFamily="sans-serif-medium"
        android:gravity="start"
        android:includeFontPadding="false"
        android:maxLines="1"
        android:ellipsize="end"/>


</androidx.constraintlayout.widget.ConstraintLayout>

它看起来像什么:实施例1

LargeBannerView 标记:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:id="@+id/large_banner_view"
    android:layout_width="match_parent"
    android:layout_height="88dp"
    android:background="@drawable/large_banner_card">

    <ImageView
        android:id="@+id/image"
        android:layout_width="190dp"
        android:layout_height="40dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        tools:src="@drawable/banner_1_img" />

    <TextView
        android:layout_marginTop="4dp"
        android:layout_marginHorizontal="12dp"
        android:id="@+id/title"
        android:gravity="center"
        android:layout_width="match_parent"
        android:layout_height="18dp"
        android:textSize="16sp"
        android:textStyle="bold"
        android:textColor="@color/black"
        tools:text="Мангоооооо 100% бонусов"
        app:layout_constraintTop_toBottomOf="@id/image"
        android:includeFontPadding="false"
        android:maxLines="1"
        android:ellipsize="end"/>

    <TextView
        android:layout_marginBottom="4dp"
        android:layout_marginHorizontal="32dp"
        android:layout_width="match_parent"
        android:layout_height="20dp"
        android:textSize="8sp"
        android:id="@+id/description"
        android:textColor="@color/black"
        app:layout_constraintTop_toBottomOf="@+id/title"
        tools:text="Покупайте что-то по что-то и что-то что-то по что-то и что-точто-то "
        android:includeFontPadding="false"
        android:maxLines="2"
        android:ellipsize="end"/>




</androidx.constraintlayout.widget.ConstraintLayout>

分别:在此输入图像描述

横幅视图标记:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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="88dp"
    android:layout_marginVertical="10dp"
    android:layout_marginHorizontal="20dp">

    <com.prod.solution.impl.ui.banner.LargeBannerView
        android:id="@+id/large"
        android:layout_width="300dp"
        android:layout_height="match_parent"
        app:layout_constraintStart_toStartOf="parent"
        tools:layout_editor_absoluteY="0dp" />

    <com.prod.solution.impl.ui.banner.SmallBannerView
        android:id="@+id/small"
        android:layout_width="88dp"
        android:layout_height="match_parent"
        app:layout_constraintStart_toEndOf="@+id/large"
        tools:layout_editor_absoluteY="0dp" />

</androidx.constraintlayout.widget.ConstraintLayout>

这是结果:在此输入图像描述

这也是 BannerView 代码:

class BannerView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0,
) : RelativeLayout(context, attrs, defStyleAttr) {

    private var binding: BannerViewBinding

    init {
        binding = BannerViewBinding.inflate(LayoutInflater.from(context))
        addView(binding.root)
    }

    fun setupBanner(model: BannerUiModel) {

        binding.large.setUpLarge(model.largeBanner)
        binding.small.setUpSmall(model.smallBanner)
    }
}

class LargeBannerView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0,
) : RelativeLayout(context, attrs, defStyleAttr) {

    private var binding: LargeBannerViewBinding

    init {
        binding = LargeBannerViewBinding.inflate(LayoutInflater.from(context))
        addView(binding.root)
    }

    fun setUpLarge(model: LargeBannerUiModel) {
        binding.title.text = model.title
        binding.description.text = model.description
        binding.image.setImageDrawable(AppCompatResources.getDrawable(context, model.imageResId))
    }
}

class SmallBannerView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0,
) : RelativeLayout(context, attrs, defStyleAttr) {

    private var binding: SmallBannerViewBinding

    init {
        binding = SmallBannerViewBinding.inflate(LayoutInflater.from(context))
        addView(binding.root)
    }

    fun setUpSmall(model: SmallBannerUiModel?) {
        binding.rightTitle.text = model?.rightLabel
        binding.leftTitle.text = model?.leftLabel

        val imageId = model?.imageResId
        if (imageId != null)
            binding.image.setImageDrawable(AppCompatResources.getDrawable(context, imageId))
    }
}

我想看到的:在此输入图像描述

我尝试删除 maxLines 和 ellipsize 参数,但这没有帮助。

android
  • 1 个回答
  • 18 Views
Martin Hope
A1pha
Asked: 2024-10-13 20:59:10 +0000 UTC

使用 re 查找文本文件中最长的子字符串

  • 7

问题条件是:

文本文件包含一串字符,其中可能包括拉丁字母 A...Z 的大写字母。求恰好包含三个 Z(不一定是相邻的)的最长子串的长度。

我想到了使用 re 库来解决这个问题:

import re

with open("text.txt") as file:
    string = file.read()

    substrings = re.findall(r"[^Z]*Z" * 3 + r"[^Z]*", string)

    print(len(max(substrings, key=len)))

但答案不匹配:正确的是338,代码显示297。你能告诉我错误是什么吗?

python
  • 4 个回答
  • 176 Views
Martin Hope
A1pha
Asked: 2024-09-08 22:56:48 +0000 UTC

如何执行 lambda 函数而不将其存储在变量中?

  • 5

我有一项任务需要所有代码都在一行上。我不会给出条件;这一切都归结为一个相当简单的表达式:

answer = a + b + c + (a ** 2 + b ** 2 + c ** 2) ** 0.5

输入数据(a、b、c)被输入到控制台,每个数字占一个新行。正如您可能已经猜到的,一行解决这个问题并不容易,因为......变量被使用两次。

这里我得出以下结论:我应该使用lambda函数并将输入数字设置为参数中的默认值:

print(lambda a=int(input()), b=int(input()), c=int(input()): a + b + c + (a ** 2 + b ** 2 + c ** 2) ** 0.5)

结论很清楚,这不是所需要的 - 将返回对函数对象的引用,因为结果,她没有被叫到。这是如何调用 lambda 函数而不将其存储在单独的变量中的问题。

PS 你不必写“;”、“eval”、“marshal”、“exec”,根据任务条款,它们是被禁止的。 PPS 输入数据:3、4、12 -> 32.0

python
  • 3 个回答
  • 68 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5