簡體   English   中英

在Android模擬器中未顯示Imagebutton

[英]Imagebutton not showing in Android Emulator

我有一個找不到解決方案的問題。 我正在通過Android SDk創建一個imagebutton,盡管它在“預覽”窗口中顯示,但在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>

您不知道toolsandroid之間的區別。 tools:src="@tools:sample/avatars"僅在IDE的預覽中顯示。 更改為android:src="@tools:sample/avatars"

檢查文檔: https : //developer.android.com/studio/write/tool-attributes

原因,您使用的是tools:src屬性而不是android:src

tool:<attributes> =僅在預覽模擬器中工作。 它只是向您顯示臨時提示。

android:<attributes> =用於定義的實際定義

例如 如果在textView中使用tool:text 它只是像提示一樣顯示主題外觀。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM