我遇到了一个无法找到解决方案的问题。我正在通过 Android SDK 创建一个图像按钮,尽管它显示在预览窗口中,但它不会显示在 Nexus 6 模拟器中。图片附在这里
xml文件的代码是
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
android:padding="10dp"
tools:context=".ViewActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textSize="@dimen/activity_bold_textsize"
/>
<ImageButton
android:id="@+id/imageButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:src="@tools:sample/avatars" />
<CheckBox
android:id="@+id/checkBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/rememberMe" />
<RadioGroup
android:id="@+id/radio_g1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/rad1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rad1"/>
<RadioButton
android:id="@+id/rad2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rad2"
/>
</RadioGroup>
<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/togb1" />
<Switch
android:id="@+id/switch1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/Switch" />
</LinearLayout>
最佳答案
你不知道tools
和android
之间的区别。
tools:src="@tools:sample/avatars"
仅在 IDE 预览中显示。
改成
android:src="@tools:sample/avatars"
查看文档:https://developer.android.com/studio/write/tool-attributes
关于java - 图像按钮未在 Android 模拟器中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53643982/