矢量绘图不显示

时间:2019-10-11 22:41:23

标签: android android-imageview android-drawable android-vectordrawable

我在约束布局中有两个图像视图都设置为默认值。我对它们的处理相同,但是一个没有出现,另一个是。我在RecyclerView中单独使用布局,在两种情况下,其中一张图像均不显示,并且始终相同。我尝试以编程方式设置图像以及设置可见性,但这并没有任何改变。

我如何设置两个图像之间的唯一区别是,显示的图像的宽度为wrap_content,而未显示的图像的宽度为match_parent。如何显示图片?

layout.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_margin="@dimen/layout_margin">

    <ImageView
        android:id="@+id/status_child_profile_picture"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toTopOf="@id/status_child_header_break"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintVertical_bias="0"

        android:src="@drawable/ic_profile_icon_1_64"
        android:tint="@color/colorGray"/>

    <TextView
        android:id="@+id/status_child_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/status_view_text_view_horizontal_margin"
        android:layout_marginStart="@dimen/status_view_text_view_horizontal_margin"

        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toRightOf="@id/status_child_profile_picture"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintHorizontal_bias="0"

        android:textSize="@dimen/person_view_name_text_size"/>

    <TextView
        android:id="@+id/status_child_status_info"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/status_view_text_view_vertical_margin"

        app:layout_constraintTop_toBottomOf="@id/status_child_name"
        app:layout_constraintLeft_toLeftOf="@id/status_child_name"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintHorizontal_bias="0" />

    <Space
        android:id="@+id/status_child_header_break"
        android:layout_width="match_parent"
        android:layout_height="@dimen/layout_margin"

        app:layout_constraintTop_toBottomOf="@id/status_child_profile_picture"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"/>

    <TextView
        android:id="@+id/status_child_status_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        app:layout_constraintTop_toBottomOf="@id/status_child_header_break"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"

        android:visibility="gone"/>

    <ImageView
        android:id="@+id/status_child_status_image"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        app:layout_constraintTop_toTopOf="@+id/status_child_header_break"
        app:layout_constraintTop_toBottomOf="@id/status_child_status_text"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"

        android:src="@drawable/ic_image_placeholder"
        android:tint="@color/colorGray"/>

    <VideoView
        android:id="@+id/status_child_status_video"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        app:layout_constraintTop_toBottomOf="@id/status_child_status_image"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintVertical_bias="0"

        android:visibility="gone"/>

    <ProgressBar
        android:id="@+id/status_child_progress_bar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"

        android:indeterminate="true"
        android:visibility="gone" />

</androidx.constraintlayout.widget.ConstraintLayout>

呼叫代码

statusChildView.setStatusImage(resources.getDrawable(R.drawable.ic_image_placeholder));

这是我的视图类:我已经尝试对两条注释行进行注释和取消注释,但这没有效果。

public class StatusChildView implements IStatusChildView {
    private static final String LOG_TAG = "Status";
    private static final String SUB_LOG_TAG = "StatusChildView";
    . . .
    private ImageView profilePicture;
    private ImageView statusImage;
    private boolean isShowImage = false;
    . . .
    @Override
    public void setProfilePicture() {

    }
    . . .
    @Override
    public void setStatusImage(Drawable value) {
        Logger.d(LOG_TAG, SUB_LOG_TAG, "Setting image: value = " + value);
        isShowImage = (value != null);
        //setVisibility(statusImage, isShowImage, true);  // this will be added to the profile picture later
        //statusImage.setImageDrawable(value);  // this will be added to the profile picture later
    }
    . . . 
    private static void setVisibility(View view, boolean isVisible, boolean setGone) {
        FlitterLogger.d(LOG_TAG, SUB_LOG_TAG, "Setting visibility: isVisible = " + isVisible + ", setGone = " + setGone);
        if (isVisible) {
            FlitterLogger.v(LOG_TAG, SUB_LOG_TAG, "Setting visibility: visible");
            view.setVisibility(View.VISIBLE);
        }
        else {
            if (setGone) {
                FlitterLogger.v(LOG_TAG, SUB_LOG_TAG, "Setting visibility: gone");
                view.setVisibility(View.GONE);
            }
            else {
                FlitterLogger.v(LOG_TAG, SUB_LOG_TAG, "Setting visibility: invisible");
                view.setVisibility(View.INVISIBLE);
            }
        }
    }
    . . .
}

记录器的结果

2019-10-11 16:20:02.257 8345-8345 / com .------.------.------ D /状态:设置图像:值= android。 graphics.drawable.VectorDrawable@46c961e(StatusChildView)

0 个答案:

没有答案