简体   繁体   中英

image isnt showing on layout preview in android studio

Am new to app development , however I have seen multiple sources online that show you how to add an image to your layout

However the image isnt being shown on the layout preview

My code is below

 <ImageView
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:scaleType="fitStart"
    app:srcCompat="@drawable/mm"
    tools:layout_editor_absoluteX="132dp"
    tools:layout_editor_absoluteY="16dp" />

I just don't know what I'm doing wrong .. I've followed multiple guides but still nothing

Image screenshot of studio showing issue : https://imgwiz.com/image/gzHD

My PC seems to be having issues freezing occasionally whe Android studio is running so am setting up a VPS with studio on it and will test all these suggestions on the new installation as that may be related to my issue

Use

<android.support.v7.widget.AppCompatImageView
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:scaleType="fitStart"
    app:srcCompat="@drawable/mm"
    tools:layout_editor_absoluteX="132dp"
    tools:layout_editor_absoluteY="16dp" />

instead of

<ImageView
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:scaleType="fitStart"
    app:srcCompat="@drawable/mm"
    tools:layout_editor_absoluteX="132dp"
    tools:layout_editor_absoluteY="16dp" />

helped me. You can replace it without any changes in your code.

In addition: Be aware of using

tools:layout_editor_absoluteX="132dp"
tools:layout_editor_absoluteY="16dp"

The namespace tools: means that it only affects your editor preview. As i saw in your screenshot, you are using a ConstraintLayout as parent layout. Consider adding app:layout_constraintBottom_toBottomOf etc to align your ImageView .

it seems that your ImageView's position is not in the viewing area of the Design/BluePrint

so I recommend to switch to Text mode and add these to your ImageView

tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="0dp" 

to make it show on the designer when move it to your desired position

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM