我需要使用安卓相機。因此我使用以下模板:https ://github.com/android/camera-samples/tree/main/Camera2SlowMotion
我在 fragment_camera.xml 中添加了一個 Butten https://github.com/android/camera-samples/blob/main/Camera2SlowMotion/app/src/main/res/layout/fragment_camera.xml
<Button
android:id="@ id/change_focus_button"
android:layout_width="115dp"
android:layout_height="81dp"
android:text="@string/focusButtonText"
tools:layout_editor_absoluteX="13dp"
tools:layout_editor_absoluteY="473dp" />
在 CameraFragment.kt 中,我現在想在單擊按鈕時呼叫一個函式。因此,據我了解,我需要創建一個 setOnClickListener。
https://github.com/android/camera-samples/blob/main/Camera2SlowMotion/app/src/main/java/com/example/android/camera2/slowmo/fragments/CameraFragment.kt
我考慮在第 309 行添加以下行。這將呼叫我然后創建的函式。但是“。” 在 fragmentCameraBinding.changeFocusButton 之后總是紅色并且不會消失。
fragmentCameraBinding.changeFocusButton.setOnClickListener { chnageFocuslen() }
我需要更改什么/我需要在哪里添加 OnClickListener?
非常感謝您!
uj5u.com熱心網友回復:
我不得不下載示例,因為我無法從您帖子中的片段中看到問題所在。
問題是CameraFragment有兩個布局檔案,一個在默認檔案夾layout中,一個在layout-land橫向方向。因此,您需要將您的change_focus_buttonXML 添加到兩個布局檔案中,以便nullable在您通過fragmentCameraBindingin訪問它時不使用它CameraFragment。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/451156.html
上一篇:點擊按鈕檢查單選或點擊單選
下一篇:更改按鈕以顯示串列?
