Android ImageView изображение не отображается - PullRequest
0 голосов
/ 18 сентября 2018

В настоящее время я работаю с изображением, чтобы отобразить векторную графику. Который он не будет отображать, но он отображает значок в androidstudio на левой стороне. Код можно увидеть ниже:

EDIT Я установил вес на 0, чтобы отобразить его в конце линейного макета. Это не ошибка ширины или высоты. Расположение не является проблемой, отображение

Как видите, вектор действителен с левой стороны. enter image description here

Код всплывающего окна:

<?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"
    android:id="@+id/report_template_edit_draft_popup"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:background="@color/pspdf__color_white"
    android:orientation="vertical">

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

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

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center_vertical"
                android:text="@string/report_template_popup_window_title"
                android:textStyle="bold" />

            <ImageView
                android:id="@+id/report_template_popup_close_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_weight="0"
                android:minHeight="30dp"
                android:minWidth="30dp"
                app:srcCompat="@drawable/ic_close" />


    </LinearLayout>

</LinearLayout>

Проблема в том, что он не отображается в дизайне, а не в приложении.

enter image description here

И да, я использую это в своем build.gradle

vectorDrawables.useSupportLibrary true

ic_close.xml

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportHeight="24.0"
        android:viewportWidth="24.0">
    <path
        android:fillColor="#ffffff"
        android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
</vector>

Ответы [ 4 ]

0 голосов
/ 18 сентября 2018

Прежде всего, не нужно добавлять android: layout_weight = "0", вы можете использовать его как ..

<?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"
    android:id="@+id/report_template_edit_draft_popup"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:orientation="vertical">

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

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

            <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center_vertical"
                android:text="some text"
                android:textStyle="bold" />

            <ImageView
                android:id="@+id/report_template_popup_close_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:minHeight="30dp"
                android:minWidth="30dp"
                app:srcCompat="@drawable/ic_dummy" />


        </LinearLayout>

    </LinearLayout>`
</LinearLayout>

Во-вторых, попробуйте использовать другой значок вектора или изменить цвет фона или вектор макетацвет значка, может быть проблема с белым по белому цвету.

0 голосов
/ 18 сентября 2018

Попробуйте это

<android.support.v7.widget.AppCompatImageView
android:id="@+id/reprt_template_popup_close_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
androi:minHeight="30dp"
androi:minWidth="30dp"
app:srcCompat="@drawable/ic_close"
/>

Вес не нужен для указанного выше

Чтобы сделать так, как вы показали на картинке

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

        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center_vertical"
            android:text="@string/report_template_popup_window_title"
            android:textStyle="bold" />

        <ImageView
            android:id="@+id/report_template_popup_close_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:minHeight="30dp"
            android:minWidth="30dp"
            app:srcCompat="@drawable/ic_close" />
</LinearLayout>
0 голосов
/ 18 сентября 2018

Посмотрите на схему ниже, я использовал android:weightSum для правильного присвоения веса виду.

<?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"
    android:id="@+id/report_template_edit_draft_popup"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:orientation="vertical">

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:weightSum="1">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="0.1"
                android:gravity="center_vertical"
                android:maxLines="1"
                android:text=" i am ravibndra kushwaha have alook on the solution"
                android:textStyle="bold" />

            <ImageView
                android:id="@+id/report_template_popup_close_button"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_weight="0.9"
                android:minHeight="30dp"
                android:minWidth="30dp"
                app:srcCompat="@drawable/ic_close" />


        </LinearLayout>

    </LinearLayout>
</LinearLayout>
0 голосов
/ 18 сентября 2018

app:srcCompat должен использоваться с AppCompatImageView.Если вы хотите использовать ImageView, вы должны использовать android:src

изменить его следующим образом:

<ImageView 
    <!-- your other attributes -->
    android:src="@drawable/ic_close"/>

или таким образом:

<android.support.v7.widget.AppCompatImageView
                        <!-- your other attributes -->
                        app:srcCompat="@drawable/ic_close"

                />

РЕДАКТИРОВАТЬ:

также удалить android:layout_weight="0" форму ImageView и заменить android:layout_width="match_parent" на android:layout_width="0dp" из TextView

EDIT2:

<android.support.v7.widget.AppCompatImageView
                        android:layout_width="30dp"
                        android:layout_height="30dp"
                        android:scaleType="fitCenter"
                        app:srcCompat="@drawable/ic_close"
                        android:adjustViewBounds="true"

                />

Чтобы создать линейный макет, в котором каждый дочерний элемент использует одинаковое количество места на экране, установите для android: layout_height каждого вида значение «0dp» (для вертикального макета) или для android: layout_width каждого вида значение «0dp "(для горизонтального расположения).Затем установите для android: layout_weight каждого вида значение «1».

https://developer.android.com/guide/topics/ui/layout/linear

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...