【发布时间】:2021-08-04 09:30:27
【问题描述】:
我是 Android 新手,不明白它是如何工作的。我有这个 XML 代码
<?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:id="@+id/mainWindow"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableLayout
android:id="@+id/katalog"
android:layout_width="388dp"
android:layout_height="179dp"
app:layout_constraintBottom_toTopOf="@+id/button5"
app:layout_constraintStart_toStartOf="parent">
<TableRow
android:id="@+id/row"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView // problem is here
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:srcCompat="@tools:sample/avatars" />
<LinearLayout
android:id="@+id/linear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textView11"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Name"
android:textSize="18sp" />
<TextView
android:id="@+id/textView12"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Description"
android:textSize="18sp" />
<TextView
android:id="@+id/textView13"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Stock"
android:textSize="18sp" />
<Button
android:id="@+id/button9"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
</TableRow>
</TableLayout>
<Button
android:id="@+id/button3"
android:layout_width="135dp"
android:layout_height="51dp"
android:text="Stuff"
app:backgroundTint="#8BC34A"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="@+id/button5"
android:layout_width="135dp"
android:layout_height="51dp"
android:layout_marginEnd="1dp"
android:layout_marginRight="1dp"
android:text="Person"
app:backgroundTint="#8BC34A"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/button6"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="@+id/button3" />
<Button
android:id="@+id/button6"
android:layout_width="135dp"
android:layout_height="51dp"
android:layout_marginStart="1dp"
android:layout_marginLeft="1dp"
android:text="card"
app:backgroundTint="#07464E"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/button5" />
</androidx.constraintlayout.widget.ConstraintLayout>
我还有另一个几乎相同的选项。但是这个没有显示。 Java 类也很少有按钮的动作监听器,而 TableLayout 没有。但是另一个带有表格布局的java类没有任何代码,就像那样
public class admpanel extends lk{
private TableLayout table;
@SuppressLint("SetTextI18n")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.admpanel);
}
}
那就行了。
附:另一个 TableLayout 没有显示,因为我忘了使用“id”作为片段,然后我修复了它。但现在我不知道
编辑:如果我删除 ImageView,该代码开始工作。如何使用图像视图?有针对性的问题
【问题讨论】:
-
嗨@Specator 你能用
android:src="@mipmap/ic_launcher"替换行tools:srcCompat="@tools:sample/avatars"并试一试吗? -
@Kartik 不起作用。但是如果我删除头像(imageView),它就会开始工作。
-
@Kartik 如果我扩展 FragmentActivity 会起作用。但仅适用于
android:src="@mipmap/ic_launcher" -
如果你也扩展 AppCompatActivity 这将起作用。
标签: android tablelayout