小编dar*_*h f的帖子

新结果 API 错误:请求代码只能使用低 16 位

今天我切换到新的ResultAPI,我遇到了这个错误:

java.lang.IllegalArgumentException: Can only use lower 16 bits for requestCode
    at androidx.fragment.app.FragmentActivity.checkForValidRequestCode(FragmentActivity.java:715)
    at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:673)
    at androidx.core.app.ActivityCompat.startActivityForResult(ActivityCompat.java:234)
    at androidx.activity.ComponentActivity$2.onLaunch(ComponentActivity.java:207)
    at androidx.activity.result.ActivityResultRegistry$3.launch(ActivityResultRegistry.java:147)
    at androidx.activity.result.ActivityResultLauncher.launch(ActivityResultLauncher.java:42)
    at .MainActivity.getVideo(MainActivity.kt:61)
    at .MainActivity.access$getVideo(MainActivity.kt:18)
    at .MainActivity$onCreate$2.onClick(MainActivity.kt:42)
    at android.view.View.performClick(View.java:5232)
    at android.view.View$PerformClick.run(View.java:21289)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:168)
    at android.app.ActivityThread.main(ActivityThread.java:5885)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
Run Code Online (Sandbox Code Playgroud)

执行这些行时:

private val takeFile = registerForActivityResult(GetContent()) {
    Log.e("MainActivity", "fileName: $it")
}

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    binding = ActivityMainBinding.inflate(layoutInflater)
    setContentView(binding.root)

    btn_get_video.setOnClickListener {
        getVideo()
    }

}


private fun getVideo() {
    takeFile.launch("video/*") …
Run Code Online (Sandbox Code Playgroud)

android onactivityresult startactivityforresult android-jetpack

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

为什么 getLocationOnScreen(location) 总是返回 0?

在我的FragmentLayoutLinearLayout有多个子视图(TextViewCardView)。我想找到所有LinearLayout视图的顶部偏移量,但我总是得到零。
这是我的代码:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    view = inflater.inflate(R.layout.fragment_detail, container, false);

    nestedScrollView = (NestedScrollView) view.findViewById(R.id.nestedScrollView);
    linearLayout = (LinearLayout) view.findViewById(R.id.lll);

    int childCount = linearLayout.getChildCount();
    int[] location = new int[2];
    for (int i = 0; i < childCount; i++) {
        View v = linearLayout.getChildAt(i);
        v.getLocationOnScreen(location);

        Log.e("locX", location[0] + "");
        Log.e("locY", location[1] + "");

    }


    return view;
}
Run Code Online (Sandbox Code Playgroud)

这是我的布局 xml :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"> …
Run Code Online (Sandbox Code Playgroud)

android view nestedscrollview

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