ImageView image not showing after loading with Picaso and linking to layout file

谁都会走 提交于 2019-12-02 08:20:35

Give height and weight to ImageView. I have tested it and works fine,

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="@+id/activity_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <!--<androidx.viewpager.widget.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="190dp"
        android:layout_marginBottom="8dp"/> -->


    <RadioGroup
            android:id="@+id/radiogroup"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

    </RadioGroup>

    <ImageView
            android:id="@+id/myImage"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_toEndOf="@+id/radiogroup"/>
</RelativeLayout>

It seems your ImageView is overlapping over RadioGroup! It's my recommendation for activity_main.xml file: app:srcCompat="@android:drawable/sym_def_app_icon" will replace with your image .

Try this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
   >

    <androidx.viewpager.widget.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="190dp"
        android:layout_marginBottom="8dp"/>


    <RadioGroup
        android:layout_below="@id/viewPager"
        android:id="@+id/radiogroup"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <RadioButton
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Demo"/>
        <RadioButton
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Demo"/>
        <RadioButton
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Demo"/>
        <RadioButton
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Demo"/>



    </RadioGroup>


    <ImageView
        android:layout_marginTop="20dp"
        android:layout_below="@id/radiogroup"
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:srcCompat="@android:drawable/sym_def_app_icon"
        android:contentDescription="TODO" />
</RelativeLayout>

Try to change your Layout because radiobutton overlaps imageview

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

      >
<RadioGroup
    android:id="@+id/radiogroup"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

</RadioGroup>

<ImageView
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:id="@+id/myImage" />
 </LinearLayout>

It seems your ImageView is overlapping over RadioGroup! It's my recommensation for activity_main.xml file:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.test.imageslider.MainActivity">

    <!--<androidx.viewpager.widget.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="190dp"
        android:layout_marginBottom="8dp"/> -->


    <RadioGroup
        android:id="@+id/radiogroup"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

    </RadioGroup>

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/myImage"
        android:layout_toEndOf="@+id/radiogroup" />
</RelativeLayout>/>

You can edit it on your own.

Hope it works!

P.S: I have edited activity_main.xml file out of IDE and may have some typo, so correct it if you found some :)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!