小编lpf*_*pfx的帖子

自动化性能

我正在使用Automapper将我的业务模型映射到ViewModel.

它有效,但速度很慢.

我有一个包含6893个对象的集合,有23个属性(测试环境,生产应该有更多).

使用循环00:02:32.8118534来映射所有内容.

var objects = // get all items (returns a collection of MyObj)
List<MyViewModel> collection = new List<MyViewModel>();
foreach (MyObj obj in objects)
{
     MyViewModel vm = Mapper.Map<MyObj, MyViewModel>(obj);
     collection.Add(vm);
}
Run Code Online (Sandbox Code Playgroud)

我试着像这样改进它:

var objects = // get all items (returns a collection of MyObj)
IEnumerable<MyViewModel> collection = mapper.Map<IEnumerable<MyObj>, IEnumerable<MyViewModel>>(objects);
Run Code Online (Sandbox Code Playgroud)

00:02:25.4527961绘制了一切.

所以它没有那么多帮助.

我的对象的属性都不是null.

这是我配置映射器的方式:

var config = new MapperConfiguration(cfg =>
        {
            cfg.CreateMap<MyObj, MyViewModel>();
            cfg.CreateMap<MyObjOtherObj, MyViewModelOtherObj>();
        });
mapper = config.CreateMapper();
Run Code Online (Sandbox Code Playgroud)

MyObj中:

public partial …
Run Code Online (Sandbox Code Playgroud)

c# performance automapper

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

显示软键盘时向上移动布局

当编辑文本获得焦点后出现软键盘时,我试图调整布局。现在,如果我有很多编辑文本并且键盘出现,则最后一个编辑文本被隐藏并且我无法向上滚动。

这是我的布局是如何构建的:

模板:

<LinearLayout>
    <LinearLayout>
        // header 1
    </LinearLayout>
    <LinearLayout>
        // header 1
    </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:orientation="vertical">
        // where I inflate view_1
    </LinearLayout>
    <LinearLayout>
        // footer
    </LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

视图 (view_1):

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:focusable="true"
        android:focusableInTouchMode="true">
        <LinearLayout>
            // ...
        </LinearLayout>
        <LinearLayout>
            // ...
        </LinearLayout>
        <LinearLayout>
            <TextView/>
            <EditText/>
            <TextView/>
            <EditText/>
            <TextView/>
            <EditText/>
            <TextView/>
            <EditText/>
        </LinearLayout>
    </LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)

我已经尝试了android:windowSoftInputMode(在 manifest.xml 上和以编程方式)的各种组合。我试图设置android:isScrollContainer="false"滚动视图,但没有。

我也试过这个答案,在我的滚动视图中放置了一个 GlobalLayoutListener ,但是当键盘出现时没有调用 onGlobalLayout 。而且isKeyboardShown总是假的。

android soft-keyboard

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

Android推送通知消息未显示

我正在使用推送通知,我无法理解我最近发现的错误.

我在Galaxy S4 Mini,Nexus 4,Galaxy Note 2,MOTO E和MOTO G上收到了推送消息.

但是在Galaxy S5上,我收到推送通知,我可以看到状态栏上的消息,但是当我拉下屏幕时,消息不存在.我看到了我的形象,但我没有看到消息本身.

有没有人对这个问题有所了解?

码:

NotificationCompat.Builder nBuilder;
nBuilder = new NotificationCompat.Builder(context)
    .setSmallIcon(smallIcon)
    .setAutoCancel(true).setTicker(message)
    .setVibrate(new long[] { 100, 250, 100, 250, 100, 250 })
    .setSound(alarmSound)
    .setPriority(Notification.PRIORITY_MAX);

NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
inboxStyle.setBigContentTitle(appName);
for (String notification : notifications) {  
    inboxStyle.addLine(notification);  
}  
nBuilder.setStyle(inboxStyle); 

nBuilder.setContentIntent(resultPendingIntent);
nBuilder.setDeleteIntent(deletePendingIntent);

mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, nBuilder.build());
Run Code Online (Sandbox Code Playgroud)

notifications android google-cloud-messaging

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

带有透明工具栏的Android DrawerLayout

我正在尝试创建一个DrawerLayout透明的Toolbar(带有hambuger图标)和一个NavigationView

这是我的布局main_activty

<android.support.v4.widget.DrawerLayout 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/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_map"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer"
        app:itemTextColor="@color/primary"
        android:background="@color/secondary"/>

</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)

这就是我定义app_bar_map布局的方式:

<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="match_parent">

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".core.MainActivity">

        <FrameLayout
            android:id="@+id/fragment_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </android.support.design.widget.CoordinatorLayout>

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize" />

    </android.support.design.widget.AppBarLayout>

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

最后,这是该onCreate方法的代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    MapFragment mapFragment = …
Run Code Online (Sandbox Code Playgroud)

android navigation-drawer android-5.0-lollipop

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