小编Ale*_*289的帖子

最后如何在 Horizo​​ntal RecyclerView 中显示部分项目以指示滚动?

我试图在这个线程中搜索答案:RecyclerView LinearLayoutManager set item count

但这并不能完全解决我的问题,因为它显示了固定项目。

我想做RecyclerView下图

在此处输入图片说明

正如您在图片中看到的,显示了 3 个项目,但右侧也显示了不完整的项目,以表明该滚动视图可以滚动。我想在recyclerView所有屏幕尺寸中都有那个部分(3 + 1/4)项目。

我使用的item布局的xml是这样的:

<?xml version="1.0" encoding="utf-8"?>

<androidx.cardview.widget.CardView
        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="150dp"
        android:layout_height="250dp"
        app:cardCornerRadius="10dp"
        android:layout_marginRight="8dp"
        app:cardElevation="3dp">

    <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="match_parent"
            android:background="@android:color/background_light">

        <ImageView
                android:layout_width="0dp"
                android:layout_height="100dp"
                app:srcCompat="@drawable/logo_apps"
                android:id="@+id/productImageView_Item"
                android:layout_marginTop="8dp"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                android:layout_marginStart="8dp"
                app:layout_constraintEnd_toEndOf="parent"
                android:layout_marginEnd="8dp"
                app:layout_constraintDimensionRatio="w,1:1"/>

        <TextView
                android:text="@string/product_name"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:id="@+id/productName_textView_item"
                android:layout_marginTop="8dp"
                app:layout_constraintTop_toBottomOf="@+id/productImageView_Item"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"
                android:layout_marginStart="4dp"
                app:layout_constraintEnd_toEndOf="parent"
                android:layout_marginEnd="4dp"
                android:textAlignment="center"
                android:minLines="1"
                android:maxLines="2"
                app:autoSizeMinTextSize="8sp"
                app:autoSizeMaxTextSize="14sp"
                android:layout_marginBottom="8dp"/>


    </androidx.constraintlayout.widget.ConstraintLayout>


</androidx.cardview.widget.CardView>
Run Code Online (Sandbox Code Playgroud)

而activity中的recycler view xml是这样的:

<ScrollView 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"
            tools:context=".Fragment.HomeFragment" android:background="@color/colorLightGrayBackground"> …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-recyclerview recyclerview-layout

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

如何使用毕加索模糊图像?

我想在使用毕加索下载后模糊我的图像。我实际上找到了一个可以为我的图像添加模糊效果的库:https : //github.com/wasabeef/picasso-transformations

这是我使用的代码:

 Picasso.get()
            .load(currentEvent.posterDownloadPath)
            .transform(BlurTransformation(25,3))
            .into(recommendedEventViewHolder.blurryImageView)
Run Code Online (Sandbox Code Playgroud)

但不幸的是我有错误:

在此处输入图片说明

我尝试了几种方法,但仍然无法正确使用该库的模糊效果。你能帮我添加模糊效果吗?也许你有不同的方式(不使用这个库)?

爪哇没问题。

android kotlin picasso

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

如何使用Android中的导航控制器以编程方式返回上一个目的地?

我有如下图所示的登录过程:

在此处输入图片说明

用户将使用以下代码从登录屏幕(中间)导航到更改密码屏幕(右侧):

 val changePassword = LoginUsingEmailFragmentDirections.actionToChangePasswordFragment()
Navigation.findNavController(fragmentView).navigate(changePassword)
Run Code Online (Sandbox Code Playgroud)

我想如果用户成功更改密码,我想让用户以编程方式返回登录屏幕。

如果我使用使用大量活动的旧方式导航,那么我通常使用 finish()

我有点困惑什么是实现这一目标的正确方法。我是否需要先在图表中采取行动,然后使用与上面类似的代码?或者有没有更方便或更好的方法来做到这一点?

android android-navigation android-jetpack android-architecture-navigation

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

Firebase 存储定价是按月收费的吗?

我目前使用 Firebase 计算火焰计划的成本。

Firestore 存储大小为 0.18 美元/GiB,存储大小为 0.026 美元/GB。

Firebase 存储的价格是按月计算和收费的吗?

如果我存储了 1000GB 的图像,那么在一个月内我必须支付 26 美元?

我只是想确定一下,因为定价页面中没有说明。https://firebase.google.com/pricing

firebase firebase-storage google-cloud-firestore

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

如果某些视图可见性在约束布局中消失,如何将约束设置为不同的视图?

我的主要活动中有两个不同的工具栏。我一次只显示一个工具栏。如果一个工具栏可见性可见,另一个将消失。它由 if else 语句控制

这两个工具栏被称为:

  • 通用工具栏
  • 搜索工具栏

这两个身高不一样

我正在使用include在我的主要活动中附加工具栏。

这是我的主要活动的 xml

<androidx.constraintlayout.widget.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".Activities.MainActivity" android:id="@+id/constraintLayout_main_activity">


    <include
            android:id="@+id/include_toolbar_general"
            layout="@layout/include_toolbar_general"
            android:visibility="visible"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent" android:layout_width="0dp"
            android:layout_height="wrap_content"/>

    <include
            android:id="@+id/include_toolbar_search"
            layout="@layout/include_toolbar_search"
            android:visibility="gone"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent" android:layout_width="0dp"
            android:layout_height="wrap_content"/>


    <fragment
            android:id="@+id/nav_host_fragment"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintBottom_toTopOf="@+id/bottom_nav"
            app:layout_constraintTop_toBottomOf="@+id/include_toolbar_general"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            android:name="androidx.navigation.fragment.NavHostFragment"
            app:navGraph="@navigation/main_graph"
            app:defaultNavHost="true"/>


</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

如您所见,include_toolbar_general最初是可见的。并且它下面的片段具有约束Top_toBottomOfinclude_toolbar_general

问题是,当在某些条件下,include_toolbar_general将消失。并且片段将上升并且它似乎与include_toolbar_search(可见,如果通用工具栏消失)重叠。

我想制作,当include_toolbar_general可见性消失时,它下面的片段将具有约束Top_toBottomOfinclude_toolbar_search

怎么做 ?

android android-layout android-constraintlayout

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

如果我们在 Swift 中触摸 UITextView 之外的其他区域,如何关闭键盘

在静态表视图中有 UITextView ,如果用户触摸textView 之外的其他区域,我想移除键盘

通常我可以用这行代码来移除键盘,但我不知道为什么,在 textview 中添加占位符后,它不起作用。我怀疑是因为它在静态表视图中

extension CheckinDetailTVC {

    // to remove keyboard if we touch other area
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        self.view.endEditing(false)
    }

}
Run Code Online (Sandbox Code Playgroud)

我也在 stackoverflow 中尝试了另一种解决方案,但没有人在我身上工作,比如添加手势识别器

override func viewDidLoad() {
    super.viewDidLoad()
    let tapGestureReconizer = UITapGestureRecognizer(target: self, action: "tap:")
    view.addGestureRecognizer(tapGestureReconizer)
}

func tap(sender: UITapGestureRecognizer) {
    view.endEditing(true)
}
Run Code Online (Sandbox Code Playgroud)

或在 TextViewDelegate 中添加函数,但它也不起作用

func textView(textView: UITextView, shouldChangeTextInRange range: NSRange, replacementText text: String) -> Bool {
    if text == "\n" {
        textView.resignFirstResponder()
    } …
Run Code Online (Sandbox Code Playgroud)

uitableview uitextview ios uitapgesturerecognizer swift

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

如何在通过Firebase云消息接收推送通知后显示徽章编号和声音?

我正在尝试通过Firebase云消息传递到我的iOS应用程序的推送通知.我可以完美地设置firebase控制台和APN,我可以在我的设备中获取通过Firebase控制台发送的通知.

但是,当我收到通知时,它只显示警报,没有声音,徽章中没有数字,即使我在UNAuthorizationOptions = [.alert, .badge, .sound]这里说明的 是我在应用代表中使用的代码

import UIKit
import Firebase
import UserNotifications

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, MessagingDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

        FirebaseApp.configure()


        if #available(iOS 10.0, *) {
            // For iOS 10 display notification (sent via APNS)
            UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate

            let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
            UNUserNotificationCenter.current().requestAuthorization(
                options: authOptions,
                completionHandler: {_, _ in })
        } else {
            let settings: UIUserNotificationSettings =
                UIUserNotificationSettings(types: [.alert, …
Run Code Online (Sandbox Code Playgroud)

ios firebase swift firebase-cloud-messaging

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

如何使用滚动视图制作可滚动标签?

我想制作类似文章的内容来读取包含嵌套在滚动视图中的 UIImage 和 Label 的视图控制器。

我想要文章内容不大,滚动功能被禁用,但是如果内容很大,我希望它可以滚动并且可以滚动到与标签内容高度相同的高度。

(如果内容文章不是太多,那么我不需要滚动)

在此处输入图片说明

但如果内容很多,那么我希望我可以滚动。目前,如果内容很大,我可以滚动如下

在此处输入图片说明

我试图像下面的代码一样设置底部锚点,但它不起作用。这是我用于底部标签约束和视图层次结构的自动布局

在此处输入图片说明

类 NotificationDetailVC: UIViewController {

@IBOutlet weak var notificationTitleLabel: UILabel!
@IBOutlet weak var notificationImage: UIImageView!
@IBOutlet weak var notificationDateLabel: UILabel!
@IBOutlet weak var notificationScrollView: UIScrollView!
@IBOutlet weak var notificationContentLabel: UILabel!


var dataNotification : [String:Any]?

override func viewDidLoad() {
    super.viewDidLoad()


    notificationScrollView.contentLayoutGuide.bottomAnchor.constraint(equalTo: notificationContentLabel.bottomAnchor).isActive = true

}
Run Code Online (Sandbox Code Playgroud)

}

ios autolayout swift

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

如何防止使用导航控制器按“后退”按钮后显示先前的片段?

我正在尝试使用导航控制器。我想从LoginFragment移至HomeFragment。在LoginFragment此,我使用下面的代码移至HomeFragment

Navigation.findNavController(view).navigate(homeDestination)
Run Code Online (Sandbox Code Playgroud)

但是,当我点击中的后退按钮时HomeFragment,它将返回到LoginFragment,我希望当我点击按钮时它将关闭该应用程序。

以旧的方式,如果我使用activity而不是using Fragment,那么我通常会执行以下操作来获得预期的行为:

val intent = Intent(this,HomeActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK.or(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent)
Run Code Online (Sandbox Code Playgroud)

通过使用这些标志,我可以用来获得预期的行为。但是我不使用导航控制器来实现相同的行为。

android kotlin android-navigation android-jetpack android-architecture-navigation

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

如何仅在使用 onUpdate 触发器 Firestore 云功能更改字段时触发操作?

我的事件文档title中有一个名为的字段,其中包含一个布尔值。我在我的文档中设置了 onUpdate firestore 触发器。我想如果我title的更新了,那么我会做一些事情。但如果其他字段被更新,那么我根本不会执行任何操作。怎么做 ?

如果每次文档更新时都调用下面的函数,我没问题,但我只想在title更新时才做一些进一步的操作

exports.dbEventsOnUpdate = functions.firestore
.document('events/{eventId}').onUpdate(async (change,context) => {

        try {        
            const eventID = context.params.eventId

            if (titleIsUpdated) {
               return db.doc(``).set(newData)
            } else {
               // do nothing here
               return null
            }

        } catch(error) {
            console.log(error)
            return null
        }

    })
Run Code Online (Sandbox Code Playgroud)

firebase google-cloud-functions google-cloud-firestore

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