У меня есть два представления изображения в макете ограничения, оба установлены в значение по умолчанию. Я отношусь к ним одинаково, но один не появляется, а другой есть. Я использую макет в 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 / Status: Настройка изображения: value = android.graphics.drawable.VectorDrawable@46c961e (StatusChildView)