小编Bug*_*pen的帖子

ScrollView中没有释放动力

在我的活动中,我有两个RecyclerViews ScrollView.问题是当我轻扫/轻弹时ScrollView,滚动立即停止.是否有办法ScrollView实现动量或惯性,所以在滚动停止之前有一些减速?

我的XML如下:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<ProgressBar
    android:id="@+id/threadload_progress"
    style="?android:attr/progressBarStyleLarge"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:visibility="gone" />
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <android.support.v7.widget.RecyclerView 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/subforums"
        android:name="net.polunom.forum.fragments.ThreadFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layoutManager="LinearLayoutManager"
        tools:context=".fragments.ThreadFragment"
        tools:listitem="@layout/fragment_subforum"/>

    <android.support.v7.widget.RecyclerView 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/threadlist"
        android:name="net.polunom.forum.fragments.ThreadFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layoutManager="LinearLayoutManager"
        tools:context=".fragments.ThreadFragment"
        tools:listitem="@layout/fragment_thread"/>

</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)

android scrollview

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

Flutter 深度链接

根据 Flutter 的官方深度链接页面,我们不需要任何插件或原生 Android/iOS 代码来处理深度链接。

但它并没有真正告诉我们如何从该链接获取数据。我是从编码的角度来谈论的。当然,他们在那里写道:

在此输入图像描述

但这并没有告诉我应该在哪里编写什么代码才能真正获得完整的链接。我已经查找了示例/教程,但我找不到任何不使用插件来处理深度链接的内容。

现在,我所做的就是在文件<intent-filter>中添加标签AndroidManifest.xml,然后单击链接,我的应用程序就开始显示。但我不知道如何从该链接中提取数据。

有人可以在这里指导我吗?提前致谢。

android routes deep-linking flutter

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

应用程序打开时不显示通知

应用程序运行时不显示通知。当应用程序关闭时它会起作用。

MyFirebaseMessagingService.java

    public class MyFirebaseMessagingService extends FirebaseMessagingService {
    private static final String TAG = MyFirebaseMessagingService.class.getSimpleName();

    private NotificationUtils notificationUtils;

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Log.e(TAG, "From: " + remoteMessage.getFrom());

        if (remoteMessage == null)
            return;

        // Check if message contains a notification payload.
        if (remoteMessage.getNotification() != null) {
            Log.e(TAG, "Notification Body: " + remoteMessage.getNotification().getBody());
            handleNotification(remoteMessage.getNotification().getBody());
        }

        // Check if message contains a data payload.
        if (remoteMessage.getData().size() > 0) {
            Log.e(TAG, "Data Payload: " + remoteMessage.getData().toString());

            try {
                JSONObject json = new …
Run Code Online (Sandbox Code Playgroud)

notifications android push-notification foregroundnotification

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

onCreateView Fragment未调用

我有一个DialogFragment 带有FrameLayout容器的自定义,我想放一个容器,Fragment但它的视图总是返回null,我该怎么办?

DialogCreateAccount.java

   public class DialogCreateAccount extends DialogGeneral implements OnClickListener{

   @Override
   public Dialog onCreateDialog(Bundle savedInstanceState) {
    // TODO Auto-generated method stub

    Dialog dialog = super.onCreateDialog(savedInstanceState);

    //........


    return dialog;

   }


@Override
public void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

     Fragment fragment = CreateAccountFragment.newInstance();


     FragmentTransaction ft = getFragmentManager().beginTransaction();

         if(fragment.getView()!=null){ // return always null

            ft.add(
                    getFrameContainer().getId(),
                    fragment
                    )
            .commit();
         }else{

         }

        Log.i("DialogCreateAccount", "fragment:" +fragment.getView());// return null
  }
Run Code Online (Sandbox Code Playgroud)

在CreateAccountFragment.java中

 public class CreateAccountFragment extends …
Run Code Online (Sandbox Code Playgroud)

java android android-fragments android-dialogfragment

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

强制RecyclerView调用onCreateViewHolder

我有一个recyclerview可以显示项目列表,小网格或大网格,这可以在运行时更改.根据用户选择的样式,我在onCreateViewHolder中扩展不同的布局.

我也RecyclerView用来在样式之间切换.我的代码看起来像这样

layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
        @Override
        public int getSpanSize(int position) {
            if(showType == ProductAdapter.SHOW_TYPE_SMALL_GRID)
                return 1;
            else
                return columnCount; //show one item per row
        }
    });

@Override
public void onClick(View v) {
    if(showType == ProductAdapter.SHOW_TYPE_SMALL_GRID)
        showType = ProductAdapter.SHOW_TYPE_LARGE_GRID;
    else
        showType = ProductAdapter.SHOW_TYPE_SMALL_GRID;


    int firstVisibleItem = layoutManager.findFirstVisibleItemPosition();
    adapter = new ProductAdapter(getActivity(), productList, showType);
    recyclerView.setAdapter(adapter);
    layoutManager.scrollToPosition(firstVisibleItem);
}
Run Code Online (Sandbox Code Playgroud)

问题是强制onCreateViewHolder被调用我每次用户更改样式时都会创建一个新的Object.还有其他办法吗?!强制onBindViewHolder()被召回我只是使用onCreateViewHolder我怎样才能获得类似onCreateViewHolder的东西?

任何不使用多个适配器的解决方案都足够好了!

android android-adapter android-recyclerview

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

LinearLayout 中的 ConstraintLayout 不起作用

我必须以编程方式将一个视图(其根视图可以是任何内容)添加到其中,LinearLayout但如果该视图是 a ConstraintLayout,它将无法按预期工作。为什么会发生这种情况,因为根据我的理解,无论父视图是什么,子视图都必须工作。我如何使这项工作?

问题非常简单,但我找不到解决此问题的任何问题。

我附上屏幕截图以显示扭曲的视图:

原始视图_____________________添加内部线性布局后的视图

在此处输入图片说明 _______ 在此处输入图片说明

这是代码:

override fun setContentView(view: View?) {
    val toolbar = layoutInflater.inflate(R.layout.view_toolbar, null, false)
    titleView = toolbar.findViewById(R.id.title) as TextView

    val finalView = LinearLayout(this)
    finalView.layoutParams = LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)
    finalView.orientation = LinearLayout.VERTICAL
    finalView.addView(toolbar)
    finalView.addView(view)
    super.setContentView(finalView)
}
Run Code Online (Sandbox Code Playgroud)

我正在覆盖活动的setContentView功能。

android android-layout android-linearlayout android-activity android-constraintlayout

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

IllegalArgumentException:没有这样的服务ComponentInfo {JobIntentService}

关于这个问题的答案没有帮助我,我已经声明了所有权限,并且已经在我的代码中接受了答案.

AppInfoJobService(CustomJobIntentService)在Android OS 8+设备上抛出以下错误,它很少发生,无法重现.我们在BaseActivity的onCreate中排队工作.我们主要有一个活动和片段.

Fatal Exception: java.lang.IllegalArgumentException: No such service ComponentInfo{<app package>AppInfoJobService}
   at android.os.Parcel.readException(Parcel.java:2009)
   at android.os.Parcel.readException(Parcel.java:1951)
   at android.app.job.IJobScheduler$Stub$Proxy.enqueue(IJobScheduler.java:211)
   at android.app.JobSchedulerImpl.enqueue(JobSchedulerImpl.java:53)
   at android.support.v4.app.JobIntentService$JobWorkEnqueuer.enqueueWork(JobIntentService.java:342)
   at android.support.v4.app.JobIntentService.enqueueWork(JobIntentService.java:522)
   at android.support.v4.app.JobIntentService.enqueueWork(JobIntentService.java:500)
   at <application package>AppInfoJobService.startWork(AppInfoJobService.java:254)
   at <application package>MyApplication.onStartStopChanged(MusicApplication.java:694)
   at <application package>AppStateMonitor.notifyStartStop(AppStateMonitor.java:150)
   at <application package>AppStateMonitor.access$000(AppStateMonitor.java:14)
   at <application package>AppStateMonitor$CreateDestroyRunnable.run(AppStateMonitor.java:71)
   at android.os.Handler.handleCallback(Handler.java:790)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loop(Looper.java:164)
   at android.app.ActivityThread.main(ActivityThread.java:6545)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:857) 
Run Code Online (Sandbox Code Playgroud)

android illegalargumentexception android-8.0-oreo jobintentservice

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

ClusterManager setOnCameraIdleListener

在尝试实现使用时ClusterManager,我注意到它已getMap().setOnCameraChangeListener(clusterManager)被弃用.看一下Github上的android-maps-utils示例,我注意到了getMap().setOnCameraIdleListener(mClusterManager);

当我尝试做同样的事情时,我得到一个错误,因为默认ClusterManager类没有实现GoogleMap.OnCameraIdleListener.

然而,在我的gradle文件中,我使用的是最新的maps-util库:

dependencies {
    compile 'com.google.maps.android:android-maps-utils:0.4.3'
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能访问最新的ClusterManager课程?谢谢

android google-maps-android-api-2 android-maps-utils

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

RecyclerView和java.lang.IndexOutOfBoundsException无效的视图持有者适配器positionViewHolder

我有一个RecyclerView可以捆绑杂货的物品。添加项目效果很好。但是,当我尝试删除项目时,应用程序崩溃了,并且出现了IndexOutOfBoundsException错误。

我面临的问题是我的onBindViewHolder()。我试图找到适配器的位置,但并没有解决问题。我也尝试过使用notifyDataSetChanged(),只是删除了我的整个列表。

我的问题是我做错了什么以及如何解决此问题?

这是Adapter类:

private class GroceryAdapter extends RecyclerView.Adapter<GroceryHolder>{
    private List<Grocery> groceries;
    private GroceryHolder holder;

    public GroceryAdapter(){
        setGroceries(GroceryList.get(GroceryActivity.this).getGroceries());
    }

    public void setGroceries(List<Grocery> groceries){
        this.groceries = groceries;
    }

    @Override
    public GroceryHolder onCreateViewHolder(ViewGroup parent, int viewType){
        LayoutInflater layoutInflater= LayoutInflater.from(GroceryActivity.this);
        View view=layoutInflater.inflate(R.layout.grocery_list_row, parent, false);
        holder =new GroceryHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(final GroceryHolder holder, final int position){
        final Grocery grocery = groceries.get(position);
        holder.bindGrocery(grocery);
        //private Grocery grocery;
        holder.deleteImageButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View …
Run Code Online (Sandbox Code Playgroud)

java android indexoutofboundsexception android-viewholder android-recyclerview

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

RecyclerView 中的中心列

我正在尝试创建动态RecyclerView布局。我使用的是GridLayoutManager三列。

我需要包装每个网格项并将列居中(如附件所示)。

我试过一个StaggeredGridLayout,我试过一个WrapGridLayoutManager 但这些都不起作用

这是我的RecyclerView

 <android.support.v7.widget.RecyclerView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/categories_grid"
        android:layout_marginTop="@dimen/feed_item_margin"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </android.support.v7.widget.RecyclerView>
Run Code Online (Sandbox Code Playgroud)

和我的RecyclerView项目:

 <LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:background="@drawable/first_time_category_unselected"
    android:layout_width="wrap_content"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/category_name"
        android:layout_marginLeft="@dimen/feed_item_margin"
        android:layout_gravity="center_vertical"
        android:textColor="@color/black_colour"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <ImageView
        android:id="@+id/category_status_icon"
        android:layout_gravity="center_vertical"
        android:background="@drawable/icon_follow"
        android:layout_marginLeft="@dimen/feed_item_margin"
        android:layout_marginRight="@dimen/feed_item_margin"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

这是我用来实现网格间距的装饰:

public class SpacesItemDecoration extends RecyclerView.ItemDecoration {
    private int halfSpace;

    public SpacesItemDecoration(int space) {
        this.halfSpace = space / 2;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State …
Run Code Online (Sandbox Code Playgroud)

android gridlayoutmanager android-recyclerview

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