android - 我不明白为什么我的按钮没有出现在我的 Android VM 上?

标签 android xml user-interface button imagebutton

我正在尝试配置我的按钮布局,尽管没有错误,但无法弄清楚为什么按钮不可见。我已经修修补补,充其量只能得到一个按钮来显示更少的所有按钮。每个图像按钮都引用存储在 drawable-ldpi 中的图像,每个图像的大小大约为 1 KB。

下面是预期的布局外观:

 _______________________
|        logo          |
|______________________|
|       search         |
|______________________|
|                      |
|     featured         |
|                      |
|______________________|
|    |     |     |     |
|    |     |     |     |
|    |     |     |     |
|    |     |     |     |
|    |     |     |     |
|    |     |     |     |
|    |     |     |     |
|____|_____|_____|_____|
|     advertisement    |
|______________________|

Android main.xml代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainlayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:id="@+id/toplayout"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="45" >

        <ImageButton
            android:id="@+id/mytastelogo"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="15"
            android:src="@drawable/mytastelogo_image" />

        <ImageButton
            android:id="@+id/search"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="10" />

        <ImageButton
            android:id="@+id/featuredpanel"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="20" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/bottomlayout"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="45" >

        <ImageButton
            android:id="@+id/mycollection"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:src="@drawable/mycollection_image" />

        <ImageButton
            android:id="@+id/myrecommendations"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:src="@drawable/myrecommendations_image" />

        <ImageButton
            android:id="@+id/topitems"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:src="@drawable/topitems_image" />

        <ImageButton
            android:id="@+id/randomitem"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:src="@drawable/randomitem_image" />
    </LinearLayout>

    <ImageButton
        android:id="@+id/advertisement"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="10" />

</LinearLayout>

最佳答案

您已将高度和宽度设置为 0 dps。你什么也看不到。尝试先解决那些 0dps。

关于android - 我不明白为什么我的按钮没有出现在我的 Android VM 上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12065397/

相关文章:

java - 我希望外部链接在我的浏览器中打开

c++ - 阿拉伯语的布局方向不是根据语言环境确定的(Mac 和 Linux)

用于极宽 Canvas 的 Android 选项

android - SOAP 抛出 java.io.IOException : HTTP request failed, HTTP 状态:500

javascript - 使用 Ajax 或 Javascript 发送 XML 请求并从其他服务器接收 XML 响应

xml - 查找单个标签内n个相同的内部标签内容

android - 在 WebView 中启用长按

android - Kotlin 扩展函数来拆分大类

python - 我可以使用 IronPython 为 Google App Engine 开发 GUI 吗?

c# - 在新的 WPF 项目中使用 Metro UI 是否值得?