小编Rom*_*iri的帖子

ConstraintLayout不尊重最大高度

我正在尝试使用ConstraintLayout创建布局组合.为了简化我的案例,我的布局应该有三个部分:

  1. 第一个布局(红色),应根据剩余空间增长并具有最大高度.
  2. 第二个布局(绿色),固定大小为150dp,应始终低于第一个布局.
  3. 第一个布局(粉红色),也有150dp的固定大小,应该与视图底部对齐.

我正在努力的部分是为第一个布局设置最大高度(红色).好像ConstraintLayout忽略了我的"最大高度语句":

app:layout_constraintHeight_max="300dp"
Run Code Online (Sandbox Code Playgroud)

这是我当前的结果(红色部分忽略了高度限制..):

在此输入图像描述

这是完整的XML:

<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:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
tools:context="com.mixtiles.android.reviewOrder.ReviewOrderActivity"
tools:layout_editor_absoluteY="25dp">


<android.support.design.widget.AppBarLayout
    android:id="@+id/appBarLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/white">
        <android.support.v7.widget.Toolbar
            android:id="@+id/review_order_toolbar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:elevation="4dp"
            android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
        </android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>

<FrameLayout
    android:id="@+id/red"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:background="@color/red"
    app:layout_constraintBottom_toTopOf="@+id/green"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHeight_max="300dp"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/appBarLayout"
    app:layout_constraintVertical_chainStyle="spread_inside">

</FrameLayout>


<FrameLayout
    android:id="@+id/green"
    android:layout_width="0dp"
    android:layout_height="150dp"
    android:background="@color/greenish"
    app:layout_constraintBottom_toTopOf="@+id/pink"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/red">

</FrameLayout>

<FrameLayout
    android:id="@+id/pink"
    android:layout_width="match_parent"
    android:layout_height="150dp"
    android:background="@color/pink"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/green">

</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

android android-constraintlayout constraint-layout-chains

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

React Native - 何时调用"componentWillUnmount"?

我正在使用导航器在页面之间导航.

Navigator.push()方法被调用时,"componentWillUnmount"法不叫我们从导航页面上.

这有点问题,因为我想取消订阅听众等.

这是正常的行为吗?什么时候实际调用"componentWillUnmount"?

react-native

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

ReactNative FlatList一次渲染所有项目?

我正在使用ReactNative的新List组件 - FlatList.

即使单元格在屏幕上实际不可见,FlatList似乎也会立即呈现所有项目.

<FlatList data={this.props.items} 
          keyExtractor={(item, index) => generateKey()}
         renderItem={this.renderStrip}/>

 renderItem = ({item}) => { 
   console.warn('rendered!');
   return <View style={{height:200, height: 100}} />
}
Run Code Online (Sandbox Code Playgroud)

根据项目的总数调用设置30个项目并且似乎"呈现"警告.

我认为FlatList类似于Android中RecycleView的工作方式,只有当它在屏幕上可见时才会呈现项目.

我错过了什么吗?它不会降低性能吗?
我希望它只能在它即将展示时呈现一个项目.

react-native react-native-flatlist

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

适用于Android的声音可视化库

我正在寻找一个可以帮助我实现声音可视化的库.Ror示例,如下所示:

在此输入图像描述

你知道任何开源/付费库吗?

android android-library

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

Android Marshmallow-如果无法访问互联网,如何避免Wi-Fi掉线

我正在编写一个无需连接互联网即可连接到热点的应用程序。似乎在某些具有Android Marshmallow的Nexus设备上,当您连接到没有互联网请求的网络时,系统会“断开” wifi连接,并且所有请求都不会发送到热点连接。

几秒钟后,会弹出一条通知,询问您是否要保持连接状态。当答案为“是”时,请求将成功发送到热点,并且您可以获得响应。

在此处输入图片说明

我遇到了以下线程:https : //android.stackexchange.com/questions/131132/force-marshmallow-to-keep-a-wi-fi-without-internet-access

但是,我正在寻找一种编程方式(针对没有根目录的设备)来解决此问题。我目前正在使用以下代码连接到Wifi网络:

public void connectTo(String capabilities, String password, String ssid) {
    WifiManager mWifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);

    WifiConfiguration conf = new WifiConfiguration();
    conf.SSID = "\"" + ssid + "\"";
    if (capabilities.contains("WPA2")) {
        conf.preSharedKey = "\"" + password + "\"";
    } else if (capabilities.contains("WPA")) {
        conf.preSharedKey = "\"" + password + "\"";
    } else if (capabilities.contains("WEP")) {
        conf.wepKeys[0] = "\"" + password + "\"";
        conf.wepTxKeyIndex = 0;
        conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
        conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
    } else {
        conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
    }

    mWifiManager.addNetwork(conf); …
Run Code Online (Sandbox Code Playgroud)

android android-wifi android-6.0-marshmallow

6
推荐指数
0
解决办法
477
查看次数

WorkManager - 永久删除定期工作人员

我使用以下代码进行了更新,每三个小时添加一个新的定期工作人员。

fun runCouponValidatorWorker() {
    val constraints = Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build()
    val worker = PeriodicWorkRequestBuilder<CouponValidatorWorker>(3, TimeUnit.HOURS).setConstraints(constraints).build()
    WorkManager.getInstance()?.enqueueUniquePeriodicWork("couponValidatorWorker", ExistingPeriodicWorkPolicy.REPLACE, worker)
}
Run Code Online (Sandbox Code Playgroud)

我想发布一个更新,它将“杀死”这个工作人员和这个工作人员的每个预定实例。

什么是最好的方法呢?

android android-workmanager

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

RecycleView 的 setInitialPrefetchItemCount 不起作用

我试图通过使用支持库 25.1 中引入的新 API 提前预取视图来提高用户在滚动图像网格时的体验,以控制 RecycleView 中预取项目的数量。

GridLayoutManager layoutManager = new GridLayoutManager(this.getContext(), PhotoGridViewHolder.SPAN_SIZE);
layoutManager.setItemPrefetchEnabled(true);
layoutManager.setInitialPrefetchItemCount(30); 
photosRecycleView.setLayoutManager(layoutManager);
... add 100 photos to the adapter ...
Run Code Online (Sandbox Code Playgroud)

我还为我的 ViewHolders 添加了日志记录,以便我可以查看绑定是否真的发生了。

void bind(final Photo photo, int position) {
    // I expcet to see 30 logs without event scrolling as the intial set to 30.
    log.d("binding photo: " + photo.getId());
    loadPhoto(photo);
}
Run Code Online (Sandbox Code Playgroud)

但是,它似乎不起作用,因为我加载了 100 张图像的列表,但我只看到了几个日志条目(只是获取了可见项目),但是我希望看到 30,因为我将它设置为这样.

android gridlayoutmanager android-recyclerview

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

启用Intel虚拟化技术

我想安装英特尔HAXM(以使Android模拟器更快),但安装程序说我的电脑"不支持虚拟化技术(VT-x)".

在BIOS中我看到我启用了虚拟化技术,而且我还有Windows Phone模拟器(需要这项技术),效果非常好.

我下载了英特尔识别工具,它说我的Proccessor不支持这项技术(虽然上面的事实和在互联网上搜索显示我的i5确实支持这项技术)..非常奇怪.

问题是什么以及为什么该实用程序显示我的计算机不支持虚拟化技术?

我认为问题出在操作系统上:Windows 8.1 64bit

识别实用程序

virtualization android intel emulation

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

带接口的架构/设计(重构帮助)

我需要你帮我做一个我不满意的设计.该应用程序正在消费RSS新闻(文章的RSS,以及每篇文章的评论RSS).

我创建了一个名为IDataService的接口,它提供了数据提供程序的基本行为.

public interface IDataService
{
    Task<List<Item>> GetItemsAsync(string url, IItemsParser parser);
    Task<List<Comment>> GetItemCommentsAsync(string url, ICommentsParser parser);
}
Run Code Online (Sandbox Code Playgroud)

如您所见,每个函数都将web服务url(在我的情况下为RSS feed url)和一些知道如何处理数据的解析器的接口作为参数.

这些是两个解析的接口:

public interface IItemsParser
{
    List<Item> ParseRawData(string rawData);
}

public interface ICommentsParser
{
    List<Comment> ParseRawData(string rawData);
}
Run Code Online (Sandbox Code Playgroud)

现在让我们具体一点,这是实现类:

public class MyRSSDataService : IDataService
{
    public async Task<List<Item>> GetItemsAsync(string url, IItemsParser parser)
    {
        using (var httpClient = new HttpClient())
        {
            var response = await httpClient.GetAsync(new Uri(url));

            if (response.IsSuccessStatusCode)
            {
                var jsonResponse = await response.Content.ReadAsStringAsync();
                List<Item> items = parser.ParseRawData(jsonResponse);

                return items;
            } …
Run Code Online (Sandbox Code Playgroud)

c# architecture rss solid-principles

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

在Android上模拟GCM推送通知

我正在尝试使用ADB在我的Android应用上模拟GCM推送通知:

adb shell am broadcast -c com.MYAPPNAME  -a com.google.android.c2dm.intent.RECEIVE -e data "SomeData"
Run Code Online (Sandbox Code Playgroud)

据我所知,我得到了积极的结果:

Broadcasting: Intent { act=com.google.android.c2dm.intent.RECEIVE cat=[com.MYAPPNAME] (has extras) }
Broadcast completed: result=-1
Run Code Online (Sandbox Code Playgroud)

但不幸的是,我的应用程序没有在我的GCMListener上收到通知.

相关清单:

    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<permission
    android:name="com.sears.devicelab.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<uses-permission android:name="com.sears.devicelab.permission.C2D_MESSAGE" />

.... some more xml ....

     <receiver
        android:name="com.google.android.gms.gcm.GcmReceiver"
        android:exported="true" >

        <!-- android:permission="com.google.android.c2dm.permission.SEND" > -->
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="com.MYAPP" />
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
        </intent-filter>
    </receiver>

    <service
        android:name=".common.gcm.AppGcmListenerService"
        android:exported="false" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        </intent-filter>
    </service>
    <service
        android:name=".common.gcm.GcmInstanceIDListenerService"
        android:exported="false" >
        <intent-filter>
            <action android:name="com.google.android.gms.iid.InstanceID" />
        </intent-filter> …
Run Code Online (Sandbox Code Playgroud)

android google-cloud-messaging

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

Android - 强制网络请求通过wifi而不是移动网络

我有一个连接到硬件设备Wi-Fi热点的应用程序.似乎Android转发请求通过其他网络(例如3G/4G)而不是热点,因为我的热点没有互联网连接.

有没有办法强迫网络流在wifi上工作?我遇到了以下功能,但它已被弃用:https: //developer.android.com/reference/android/net/ConnectivityManager.html#setNetworkPreference(int)

networking android android-wifi

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

React Native 原生 UI 组件的宽度和高度

我正在 iOS 上创建本机 UI 组件,我希望它的大小根据内容大小扩展。似乎我必须设置固定的宽度和高度才能呈现视图。知道如何解决吗?

// JS

import React from 'react';
import { View, requireNativeComponent } from 'react-native';

class StyledText extends React.Component {
render() {
    return (
        <View style={this.props.style}>
// without the height and width the compnent won't show up
            <StyledLabelReactBridge styledText={'some text'} style={{height: 100, width: 100, backgroundColor: 'red'}}/>
        </View>
    );
}
}

StyledText.propTypes = {
styledText: React.PropTypes.string,
style: View.propTypes.style
};

const StyledLabelReactBridge = requireNativeComponent('StyledLabelReactBridge', StyledText);

module.exports = StyledText;
Run Code Online (Sandbox Code Playgroud)

// 目标-C

@implementation StyledLabelReactBridgeManager

RCT_EXPORT_MODULE()

- (UIView *)view
{
return [[NewStyledLabel …
Run Code Online (Sandbox Code Playgroud)

react-native react-native-ios

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

TextBlock Windows Phone 8.1中的文本格式

我有一个字符串列表,ViewModel格式如下:

 This is an <b>example.<b>
Run Code Online (Sandbox Code Playgroud)

我希望在我的视图中有一些文本控件,它将通过DataBinding*显示格式化文本,如下所示:

这是一个例子.

我找不到任何可以表现得像这样的内置控件.

有谁知道如何处理它?

c# windows-phone-8 windows-store-apps windows-phone-8.1

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