android - AndroidStudio] 布局文件中的对象未显示在代码中
问题描述
我对android studio很陌生,想制作一个播放视频的应用程序。所以我做了一个代码:
const val REQUEST_VIDEO_CAPTURE = 1
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// This is for Audio play
//var mediaPlayer = MediaPlayer.create(this,R.raw.test_720)
//mediaPlayer.start()
var path_vid = "android.resource://${packageName}/${R.raw.test_720}"
var mediaController = MediaController(this)
**mediaController.setAnchorView(dancerView)**
}
而activity_main 如下。
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<VideoView
android:id="@+id/dancerView"
android:layout_width="414dp"
android:layout_height="738dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.666"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.571" />
<VideoView
android:id="@+id/studentView"
android:layout_width="133dp"
android:layout_height="196dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<Button
android:id="@+id/playbtn"
android:layout_width="130dp"
android:layout_height="91dp"
android:text="Play Vid"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/dancerView"
app:layout_constraintTop_toTopOf="@+id/dancerView" />
</androidx.constraintlayout.widget.ConstraintLayout>
我确定我有 dancerView:VideoView,但我无法构建代码并看到错误:未解决的参考。由于同样的错误,我也无法使用其他视图和按钮。我做错了什么?
解决方案
推荐阅读
- css - Bootstrap 4轮播链接覆盖所有其他链接
- loops - Netlogo 中的刻度循环
- r - LDA 中的主题建模之后的下一步是什么
- c# - Websocket 服务器发送自发消息(没有来自客户端的请求)
- oracle - 启用闪回会减慢 oracle 中的更新/插入速度吗?
- json - vue.js - 发送所选对象的另一个字段
- hibernate - Hibernate Search:MassIndexer 和缺少的 CDI 范围
- ios - 更改 UIImagePickerController 的 TintColor
- android - 标签布局在 RTL 中自动滚动直到结束
- angular - 如何以模板驱动形式在 mat-chip 上应用所需的验证?