[英]Android ImageView image not showing
I currently am working with an imageview to display a vector drawable. 我目前正在使用imageview显示可绘制的矢量。 Which it will not display, but it does display the icon in androidstudio on the left side.
它不会显示,但会在左侧的androidstudio中显示图标。 The code can be seen below:
该代码可以在下面看到:
EDIT I set the weight to 0 to display it at the end of the linearlayout. 编辑我将权重设置为0,以在linearlayout的末尾显示它。 It does not bug the width or height out.
它不会影响宽度或高度。 The layout is not the issue, the displaying is
布局不是问题,显示是
As you can see, the vector is valid on the left side 如您所见,向量在左侧有效
Code of popup: 弹出代码:
<?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>
The problem is that it does not show up in the design not in the application. 问题是它没有出现在设计中,而不是在应用程序中。
And yes , I am using this in my build.gradle 是的,我在build.gradle中使用它
vectorDrawables.useSupportLibrary true
ic_close.xml 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>
First of all, no need to add android:layout_weight="0", you can use it like.. 首先,不需要添加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>
Second, try to use different vector icon or change layout background color or vector icon color, may be the issue with the white over white color. 其次,尝试使用不同的矢量图标或更改布局背景颜色或矢量图标颜色,这可能是白上白的问题。
app:srcCompat
must be used with AppCompatImageView
. app:srcCompat
必须与AppCompatImageView
一起使用。 If you want to use ImageView, you have to use android:src
如果要使用ImageView,则必须使用
android:src
change it in this way: 以这种方式更改它:
<ImageView
<!-- your other attributes -->
android:src="@drawable/ic_close"/>
or in this way : 或者以这种方式:
<android.support.v7.widget.AppCompatImageView
<!-- your other attributes -->
app:srcCompat="@drawable/ic_close"
/>
EDIT: 编辑:
also remove android:layout_weight="0"
form ImageView
and replace android:layout_width="match_parent"
with android:layout_width="0dp"
from TextView 还要从
ImageView
删除android:layout_weight="0"
并将android:layout_width="match_parent"
替换为android:layout_width="0dp"
EDIT2: 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"
/>
To create a linear layout in which each child uses the same amount of space on the screen, set the android:layout_height of each view to "0dp" (for a vertical layout) or the android:layout_width of each view to "0dp" (for a horizontal layout).
要创建每个孩子在屏幕上使用相同空间的线性布局,请将每个视图的android:layout_height设置为“ 0dp”(对于垂直布局)或将每个视图的android:layout_width设置为“ 0dp”(用于水平布局)。 Then set the android:layout_weight of each view to "1".
然后将每个视图的android:layout_weight设置为“ 1”。
https://developer.android.com/guide/topics/ui/layout/linear https://developer.android.com/guide/topics/ui/layout/linear
Try this 尝试这个
<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"
/>
Weight is not needed for the one above 上面的那一个不需要重量
To make it like you showed in the image 使它像您在图像中显示的那样
<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>
Have a look on the below layout, i have used the android:weightSum
for the properly assign the weight to the view. 看一下下面的布局,我已经使用
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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.