小编Coo*_*ind的帖子

在 Glide 中制作方形图像,然后将其四舍五入

我解决了一个典型的图像任务:尝试centerCrop()如何使用 Glide 库对图像进行舍入?,但结果似乎是Glide 圆形图像被裁剪在此处输入图片说明

(非圆形)。

我认为 Glide (v.4) 没有正确裁剪图像。我尝试了许多变体,例如GlideApp.with(photo).load(url).circleCrop().into(photo). 可能更好的是首先从矩形创建一个正方形,然后使其成为圆形。

这是 XML 的一部分:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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="wrap_content"
    >

    <ImageView
        android:id="@+id/photo"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_marginStart="15dp"
        android:layout_marginLeft="15dp"
        android:layout_marginTop="20dp"
        android:adjustViewBounds="true"
        android:scaleType="fitCenter"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:src="@drawable/image_1"
        />

    <TextView
        android:id="@+id/name"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:layout_marginStart="7dp"
        android:layout_marginLeft="7dp"
        android:lineSpacingExtra="1sp"
        android:textColor="@color/black"
        android:textSize="20sp"
        app:layout_constraintEnd_toStartOf="parent"
        app:layout_constraintHorizontal_weight="1"
        app:layout_constraintStart_toEndOf="@+id/photo"
        app:layout_constraintTop_toTopOf="@+id/photo"
        tools:text="Name"
        />

</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

更新

抱歉,源图像有问题。我不认为它是用上下白色填充物平方的(添加了线条):

在此处输入图片说明

另一个例子:

在此处输入图片说明

这是因为在后端,他们缩小了矩形图像,使其成为带有白色边框的正方形

android android-glide

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

MaterialComponents AlertDialog 文本颜色

阅读MaterialComponents 主题警报对话框按钮https://medium.com/@lcdsmao/material-design-custom-alert-dialog-5a9cab3ade11我设置AlertDialog了新材料主题的按钮和文本颜色。

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

    <!-- AlertDialog -->
    <item name="materialAlertDialogBodyTextStyle">@style/MaterialAlertDialogTextTheme</item>
    <item name="materialAlertDialogTheme">@style/MaterialAlertDialogButtonsTheme</item>
</style>

<!-- AlertDialog text -->
<style name="MaterialAlertDialogTextTheme" parent="MaterialAlertDialog.MaterialComponents.Body.Text">
    <item name="android:textColor">@color/colorPrimary</item>
    <item name="android:colorAccent">@color/colorPrimary</item>
    <item name="colorAccent">@color/colorPrimaryitem>
    <item name="android:textSize">14sp</item>
    <item name="android:textStyle">bold</item>
</style>

<!-- AlertDialog buttons -->
<style name="MaterialAlertDialogButtonsTheme" parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
    <item name="buttonBarPositiveButtonStyle">@style/AlertDialog.Button</item>
    ...
Run Code Online (Sandbox Code Playgroud)

创建AlertDialogFragment使用后

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
    super.onCreateDialog(savedInstanceState)

    return MaterialAlertDialogBuilder(context!!).apply {
        ...
    }.create()
} …
Run Code Online (Sandbox Code Playgroud)

android android-alertdialog material-design material-components material-components-android

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

片段中的getContext()

getContext()在哪里可以访问Fragment?我的意思是,它不是null,可以使用(例如,用于控件创建)。是不是onAttachonCreateView还是onActivityCreated

android android-context android-fragments

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

枚举或带字符串的密封类

我可以创建enumsealed classKotlin包含字符串资源?

例如,我有这个课:

private enum class Item(
    val id: Int,
    @DrawableRes val imageRes: Int,
    val title: String
) {
    PURSE(1, R.drawable.ic_card, "My balance"),
    MESSAGES(2, R.drawable.ic_bell, "Messages")
}
Run Code Online (Sandbox Code Playgroud)

如果val resources: Resources在构造函数中添加字段,则无法设置参数resources,因此无法使用中的字符串资源strings.xml。在这种情况下,我无法将本地化用于enum

enums android kotlin

2
推荐指数
1
解决办法
206
查看次数