代码之家  ›  专栏  ›  技术社区  ›  BrianM

Android ImageView图像未显示

  •  0
  • BrianM  · 技术社区  · 7 年前

    我目前正在使用imageview来显示一个可绘制的向量。它不会显示,但会在左侧的androidstudio中显示图标。代码如下:

    编辑 我将权重设置为0以在linearlayout的末尾显示它。它不会把宽度或高度漏掉。

    如您所见,向量在左侧是有效的 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

    是的,我正在我的生活中使用这个构建.gradle

    vectorDrawables.useSupportLibrary true
    

    集成电路_关闭.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 回复  |  直到 7 年前
        1
  •  0
  •   Ravindra Kushwaha    7 年前

    看看下面的布局,我已经用过了 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>
    
        2
  •  1
  •   Pardeep Raman    7 年前

    首先,不需要添加安卓:布局重量=“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>
    

        3
  •  0
  •   Nandu Dharmapalan    7 年前

    试试这个

    <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>
    
        4
  •  0
  •   Mahdi Rajabi    7 年前

    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" 从文本视图

    编辑2:

    <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:布局高度每个视图的 到“0dp”(对于水平布局)。然后设置安卓:布局重量

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