【问题标题】:Can not get ImageView to display无法让 ImageView 显示
【发布时间】:2014-05-04 00:03:18
【问题描述】:

我的意图是在滚动视图上创建一个小部件列表,在它们后面的屏幕中心有一个 ImageView。这就是我所拥有的,当一切都说完之后会有更多的按钮:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
    android:contentDescription="@string/description"
    android:src="@drawable/myImage" 
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:scaleType="centerInside" />


<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:layout_centerVertical="true"        
    android:background="@android:color/transparent">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:gravity="center"        
        android:orientation="vertical"
        android:background="@android:color/transparent">


        <Button xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/newButton"
            style="@style/homeScreenButton"
            android:text="@string/new_profile" />

        <Button xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/loadButton"
            style="@style/homeScreenButton"
            android:text="@string/load_profile" />

        <Button xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/calculatorButton"
            style="@style/homeScreenButton"
            android:text="@string/calculator" />

    </LinearLayout>

</ScrollView>

</RelativeLayout>

在 Eclipse 的 xml 图形布局解释器上,屏幕按预期显示。我尝试过的 2 个不同的模拟器 Android 2.2 和 Android 4.0.3 也是如此。但是当我发送到我的实际设备时,Droid 4 w/Android 4.1.2 图像根本不显示。我什至尝试让 ScrollView 透明(android:alpha="0"),认为它以某种方式覆盖了图像,但没有。任何建议将不胜感激。

【问题讨论】:

    标签: android xml


    【解决方案1】:

    尝试从 ImageView 中消除这一行,

     xmlns:android="http://schemas.android.com/apk/res/android"
    

    它应该只存在于 RelativeLayout

    这样你的 xml 文件就变成了

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    
    <ImageView 
    android:contentDescription="@string/description"
    android:src="@drawable/myImage" 
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:scaleType="centerInside" />
    
    
    <ScrollView 
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:layout_centerVertical="true"        
    android:background="@android:color/transparent">
    
    <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:gravity="center"        
        android:orientation="vertical"
        android:background="@android:color/transparent">
    
    
        <Button 
            android:id="@+id/newButton"
            style="@style/homeScreenButton"
            android:text="@string/new_profile" />
    
        <Button 
            android:id="@+id/loadButton"
            style="@style/homeScreenButton"
            android:text="@string/load_profile" />
    
        <Button 
            android:id="@+id/calculatorButton"
            style="@style/homeScreenButton"
            android:text="@string/calculator" />
    
    </LinearLayout>
    
    </ScrollView>
    
    </RelativeLayout>
    

    【讨论】:

    • 不,当我删除该行时没有任何变化。无论如何感谢您的建议。
    【解决方案2】:

    我想通了,代码很好。我的问题是图像在 /res/drawable 中,但它需要在 /res/drawable-hdpi 中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-07
      • 1970-01-01
      • 2015-07-31
      • 2019-04-18
      • 2023-03-20
      • 1970-01-01
      • 2023-03-29
      • 1970-01-01
      相关资源
      最近更新 更多