Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 仅显示选定图片的图库_Android_Gallery - Fatal编程技术网

Android 仅显示选定图片的图库

Android 仅显示选定图片的图库,android,gallery,Android,Gallery,我在安卓2.3.6和2.3.1上工作 我对多媒体资料有不想要的行为:无法显示来自多媒体资料项目的图片 My Gallery占据了所有可用空间,包含ImageView和TextView的布局设置为WRAP\u CONTENT,但仍然占据了所有屏幕,因此侧边项目超出了范围 这是图库的xml <RelativeLayout xmlns:a="http://schemas.android.com/apk/res/android" a:layout_width="match_parent"

我在安卓2.3.6和2.3.1上工作

我对
多媒体资料
有不想要的行为:无法显示来自多媒体资料项目的图片

My Gallery占据了所有可用空间,包含
ImageView
TextView
的布局设置为
WRAP\u CONTENT
,但仍然占据了所有屏幕,因此侧边项目超出了范围

这是图库的xml

<RelativeLayout xmlns:a="http://schemas.android.com/apk/res/android"
    a:layout_width="match_parent"
    a:layout_height="match_parent"
    a:layout_margin="0dp"
    a:padding="0dp">

    <ImageView
        a:id="@+imagePopup/selected"
        a:layout_width="60dp"
        a:layout_height="35dp"
        a:layout_alignParentLeft="true"
        a:layout_alignParentTop="true"
        a:src="@drawable/ic_cancel"
        a:contentDescription="@string/lng" />
    <TextView
        a:id="@+imagePopup/title"
        a:layout_alignParentTop="true"
        a:layout_toRightOf="@+imagePopup/selected"
        a:layout_alignWithParentIfMissing="true"
        a:layout_width="match_parent"
        a:layout_height="35dp"
        a:background="@drawable/rounded"
        a:text="dynamic text"
        a:textSize="23dp"
        a:textColor="#ffffffff"
        a:gravity="center"
        style="@style/trad"/>
    <Gallery
        a:id="@+imagePopup/gallery"
        a:layout_width="match_parent"
        a:layout_height="match_parent"
        a:layout_below="@+imagePopup/title"
        a:layout_alignWithParentIfMissing="true"
        a:background="#ff000000"/>
</RelativeLayout>

及其内容xml

<RelativeLayout xmlns:a="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    a:layout_width="wrap_content"
    a:layout_height="wrap_content"
    a:background="#ffff55ee">

    <ImageView
        a:id="@+imageContent/imageView"
        a:layout_width="wrap_content"
        a:layout_height="wrap_content"
        a:layout_alignParentTop="true"
        a:padding="0dp"
        a:layout_margin="0dp"
        a:src="@drawable/ic_cancel" />

    <TextView
        a:id="@+imageContent/textOver"
        a:layout_width="wrap_content"
        a:layout_height="wrap_content"
        a:layout_alignParentTop="true"
        a:layout_centerHorizontal="true"
        a:layout_marginTop="4dp"
        a:shadowColor="#FF000000"
        a:shadowRadius="4"
        a:textColor="#ffffffff"
        a:textSize="16dp"
        a:textStyle="bold" />

</RelativeLayout>

我在图片容器的背景上加了一个难看的背景色(
RelativeLayout
),以显示它的行为:

有人能告诉我我做错了什么吗。。。我就是无法摆脱它


提前谢谢^ ^

我想问题在于你的形象。您正试图显示一个更可能覆盖整个屏幕的巨大图像

您必须为图像提供一些预定义的宽度和高度属性

而不是像下面那样包装您提供的内容

  <ImageView
        a:id="@+imageContent/imageView"
        a:layout_width="wrap_content"
        a:layout_height="wrap_content"
        a:layout_alignParentTop="true"
        a:padding="0dp"
        a:layout_margin="0dp"
        a:src="@drawable/ic_cancel" />

试着提供这样的东西

  <ImageView
    a:id="@+imageContent/imageView"
    a:layout_width="150dip"
    a:layout_height="150dip"
    a:layout_alignParentTop="true"
    a:padding="0dp"
    a:layout_margin="0dp"
    a:src="@drawable/ic_cancel" />

注意:我在这里指定的布局宽度和高度只是虚构的。你必须提供你自己的

您必须知道包裹内容、填充父项和实际硬编码宽度和高度之间的差异

  • 包裹内容-这意味着,它将使用实际图像的宽度和高度

  • 填充父级-无论图像大小如何,它都占据整个屏幕

  • 通过我们自己的方式提供高度和宽度,您可以通过提供特定的宽度和高度属性来统一显示图像的大小


  • 最后,我找到了一种更好的方法,更“自然”,因为我需要: 以下是我代码的修改部分:

    <RelativeLayout xmlns:a="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        a:layout_width="wrap_content"
        a:layout_height="match_parent"
        tools:ignore="ContentDescription">
    
        <ImageView
            a:id="@+imageContent/imageView"
            a:layout_width="wrap_content"
            a:layout_height="match_parent"
            a:layout_alignParentTop="true"
            a:scaleType="fitXY"
            a:adjustViewBounds="true"
            a:src="@drawable/ic_cancel" />
    
    
    

    scaleType=“fitXY”
    adjustViewBounds=“true”
    很快就成功了,这要归功于android:spacing=“5dp”尝试此图库属性在图库上放置什么都不做(已经尝试过,只是再次尝试过…)尝试你的提示,但这将是我见过的最糟糕的行为。。。既然高度自动匹配,宽度保持成比例,为什么包装的容器会保持这么大??只是没有意义…非常感谢,我在下面发布了我找到的解决方案,谢谢你。