【问题标题】:ImageView not showing in linear layout that is inside a scrollviewImageView 未在滚动视图内的线性布局中显示
【发布时间】:2020-10-05 14:39:33
【问题描述】:

我试图在我的滚动视图中有两个可滚动的项目,所以我将一个线性布局放入滚动视图中,并在线性布局中放入一个图像视图和一个文本视图。 textview 显示,但 imageview 没有。这里有什么问题?

<?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:paddingStart="@dimen/layout_padding"
    android:paddingEnd="@dimen/layout_padding"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/name_text"
        style="@style/NameStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/name"
        android:textAlignment="center" />

    <ImageView
        android:id="@+id/star_image"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:contentDescription="@string/yellow_star"
        app:srcCompat="@android:drawable/btn_star_big_on" />


    <ScrollView
        android:id="@+id/bio_scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent">


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/profile_picture"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="@dimen/layout_margin"
                android:contentDescription="@string/profile_picture"
                tools:srcCompat="@mipmap/image" />

            <TextView
                android:id="@+id/bio_text"
                style="@style/NameStyle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:lineSpacingMultiplier="1.2"
                android:text="@string/bio" />
        </LinearLayout>

    </ScrollView>

</LinearLayout>

【问题讨论】:

  • tools:srcCompat 属性应该有 app 前缀;即app:srcCompat.
  • 有可能如果您没有在运行时将图像设置为profile_picture,那么它将不会显示..因为您使用的是tools:srcCompat..

标签: android xml android-studio android-linearlayout android-scrollview


【解决方案1】:

已解决:我错过了这一行:app:srcCompat="@mipmap/image"

我觉得自己很笨

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-16
    相关资源
    最近更新 更多