小编dav*_*aya的帖子

RecyclerView项目中的Android百分比屏幕宽度

如何将RecyclerView的物品高度设置为屏幕高度的30%?

我不能简单地使用ConstraintLayout或PercentFrameLayout/PercentRelativeLayout,因为那些位置子布局相对于父布局,其大小可能与屏幕不匹配.

最好,我想在纯XML中执行此操作(并且不必使用任何Runnables来动态获取屏幕高度).

编辑

澄清一下,由于许多解决方案建议限制RecyclerView的高度,这不是意图.RecyclerView仍应填充屏幕.这就是我所说的,使用屏幕宽度(而不是高度):

在此输入图像描述

我们的想法是将卡的宽度设置为屏幕宽度的33%,同时保持RecyclerView的宽度不变,因为它横向滚动屏幕.

android android-recyclerview android-constraintlayout

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

汉堡菜单旋转到新活动的箭头

我注意到,随着Android最近的Gmail更新,当您点击其中一封电子邮件时,会打开一个新的活动(我假设它不是因为后退箭头而产生的碎片).

但是,新活动的后退箭头不会像默认情况那样显示.主界面汉堡菜单旋转成动画中的箭头(请参阅此处的视频:http://material-design.storage.googleapis.com/publish/material_v_3/material_ext_publish/0B3T7oTWa3HiFbFRfT196SWRyS2s/animation_delightfuldetails_wellcrafted.webm)

(注意:新打开的电子邮件可能是一个片段,因为工具栏没有更改,默认的新活动动画不播放.我不确定它是哪一个.)

澄清:我知道如何让汉堡包菜单在按下/打开导航抽屉时变成箭头.事实上,我故意禁用所说的动画,因为它违反了规范.(参见这篇文章:http://www.androidpolice.com/2014/10/30/google-turns-design-inconsistency-ten-latest-round-navigation-drawers/).但是,我想知道,如果在创建新的片段/活动时可以使用相同的动画,无论Gmail使用哪一个.

android android-animation android-activity android-actionbar hamburger-menu

12
推荐指数
1
解决办法
1315
查看次数

Android Layer-List VectorDrawable大小

我的问题与这个问题有关:链接.我最近将用于Android的大部分资源从用于不同分辨率的不同png文件更改为矢量绘图.我正在使用"滑动到删除"库,可以在滑动过程中更改其视图的背景,以显示带有垃圾桶图标的Gmail风格红色背景,类似于此(具有绿色背景和支票)图标):

在此输入图像描述

我曾经使用以下代码执行此操作,而我仍然使用<API 21

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <color android:color="@color/accent"/>
    </item>
    <item android:right="@dimen/activity_horizontal_margin">
        <bitmap
            android:gravity="right|center_vertical"
            android:src="@drawable/ic_delete_24dp"/>
    </item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)

但是,API 21+需要不同的语法

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <color android:color="@color/accent" />
    </item>
    <item android:right="@dimen/activity_horizontal_margin"
          android:drawable="@drawable/ic_delete_24dp"
          android:gravity="right|center_vertical"/>
</layer-list>
Run Code Online (Sandbox Code Playgroud)

现在,API 21和API 22(Lollipop)上的图标将被拉伸以填充屏幕,而不是左/右侧的图标.有没有办法指定图标的宽度?

android background layer-list android-vectordrawable

10
推荐指数
1
解决办法
4469
查看次数

Swift Dictionary:删除时间复杂度

正如官方网站所述,从字典(或地图,其他语言)中删除密钥是Swift中的O(n),使其成为一种效率低下的操作.

为什么不是O(1)如果put()和get()应该是基于散列的O(1)?

在此输入图像描述

time-complexity swift

7
推荐指数
1
解决办法
455
查看次数

工具:RecyclerView项目的文本

我知道你设置的时候

tools:text="Sample text"
Run Code Online (Sandbox Code Playgroud)

在a中TextView,您将在Android Studio的预览模式下看到示例文本,但不会在实际应用中看到.我想为a中的项目做这个RecyclerView,但我似乎无法做到.这是我到目前为止所做的:

在RecyclerView(名为content_feed)中:

tools:listitem="@layout/cell_feed"
Run Code Online (Sandbox Code Playgroud)

在单元格中(名称为cell_feed):

tools:showIn="@layout/content_feed"
Run Code Online (Sandbox Code Playgroud)

这是xml文件:

cell_feed.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="@dimen/height_feed_cell"
    android:layout_marginLeft="@dimen/margin_feed_cell"
    android:layout_marginRight="@dimen/margin_feed_cell"
    android:orientation="horizontal"
    tools:showIn="@layout/content_feed">

    <LinearLayout
        android:id="@+id/timeLayouts"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:alpha="@dimen/alpha_feed_secondary_text"
            android:textSize="@dimen/size_feed_secondary_text"
            android:id="@+id/startTimeText"
            tools:text="8:00 AM"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:alpha="@dimen/alpha_feed_secondary_text"
            android:textSize="@dimen/size_feed_secondary_text"
            android:id="@+id/endTimeText"
            tools:text="10:00 AM"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/margin_feed_cell_text"
        android:layout_toRightOf="@+id/timeLayouts"
        android:layout_centerVertical="true"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/margin_bottom_feed_cell_title"
            android:textSize="@dimen/size_feed_cell_title"
            android:textStyle="bold"
            android:id="@+id/titleText"
            tools:text="Event title"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:alpha="@dimen/alpha_feed_secondary_text"
            android:textSize="@dimen/size_feed_secondary_text"
            android:id="@+id/captionText"
            tools:text="Event caption"/>
    </LinearLayout>

    <CheckBox
        android:layout_width="wrap_content" …
Run Code Online (Sandbox Code Playgroud)

android android-studio android-recyclerview android-tools-namespace android-layout-editor

6
推荐指数
1
解决办法
2337
查看次数

React Native + Appium iOS elementByAccessibilityId.text()

我正在使用 Appium + Jest 为 Android 和 iOS 编写 React Native 测试。

这是我的 React Native 元素:

<Text accessibilityLabel={'emailError'}>Invalid email</Text>
Run Code Online (Sandbox Code Playgroud)

这是我创建的用于提取 React Native 元素的值的 Promise 链Text

driver.elementByAccessibilityId('emailError')
      .then(error => error.text())
      .then(errorText => expect(errorText).toBe('Invalid email'))
Run Code Online (Sandbox Code Playgroud)

在 Android 上,此测试通过。在 iOS 上,此测试失败,并且errorText === 'emailError'.

为什么会这样?是否有跨平台的解决方案来提取文本?

appium reactjs jestjs e2e-testing react-native

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