标签: android-imageview

ImageView填充父级的宽度或高度,但保持纵横比

我有一个方形图像(虽然这个问题也适用于矩形图像).我想尽可能大地显示图像,必要时拉伸它们以填充它们的父母,同时仍然保持纵横比.图像小于ImageView.问题是,我无法拉伸图像并"匹配"ImageView的高度和宽度.

这是我的XML布局文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:padding="10dp">

    <ImageView android:id="@+id/image"
               android:layout_width="fill_parent"
               android:layout_height="fill_parent"
               android:adjustViewBounds="true"
               android:scaleType="fitCenter"
               android:layout_marginTop="10dp"/>

    <TextView android:id="@+id/name"
              android:layout_below="@id/image"
              android:layout_alignLeft="@id/image"
              android:layout_marginTop="20dp"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:textSize="18dp"/>

    <TextView android:id="@+id/name2"
              android:layout_below="@id/name"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:textSize="14dp"/>


</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

我已经使用的多种组合fill_parent,wrap_content与多个scaleTypes: ,fitCenter,fitStart,fitEnd,centerInside他们都画在正确的纵横比的图像,但没有人真正缩放图像UP和ImageView的本身,导致无论是在TextViews被推所有屏幕下方,ImageView内部空白区域,图像未缩放或图像裁剪.

我无法为此找到合适的组合.

android android-layout android-imageview android-relativelayout

41
推荐指数
4
解决办法
6万
查看次数

Android布局 - 与ImageView对齐问题

我试图将图像放在a的左上角LinearLayout,但是图像边框和填充占据了窗口的整个宽度.

如果我尝试下面的XML,我会在页面的整个宽度上获得带有边框和白色背景的图像,除了图像最终居中,并且不会向左移动.

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="left"
    android:src="@drawable/banner"
    android:background="@android:color/white"
    android:padding="@dimen/d_8px"
/>
Run Code Online (Sandbox Code Playgroud)

是否有一些我尚未发现的属性强制图像在设置为何ImageView时保持对齐?layout_widthfill_parent

在平均时间里,我已经解决了这个问题,将ImageView内部另一个放入其中LinearLayout,然后TextView在其右侧放空,占据了其余的水平空间.

layout android android-imageview

40
推荐指数
2
解决办法
7万
查看次数

Android ImageView修复图像大小

我有一个Android应用程序,我有一个ImageView,我需要保持大小不变​​,我需要放入ImageView不同大小的各种图像.

我只需要确保所有图像都必须适合ImageView,如果图像较小则图像应该增大,并且如果图像较大则应该减小.

非常感谢你的时间.

android imageview android-imageview

40
推荐指数
4
解决办法
15万
查看次数

如何在android中避免相对布局中的重叠视图?

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:textSize="30sp" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/textView1"
        android:textSize="20sp" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/textView2"
        android:textSize="20sp" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/textView3"
        android:textSize="20sp" />

    <TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/textView4"
        android:textSize="20sp" />

    <TextView
        android:id="@+id/textView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/textView5"
        android:textSize="20sp" />

    <TextView
        android:id="@+id/textView7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/textView6"
        android:textSize="20sp" />

    <TextView
        android:id="@+id/textView8"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/textView7"
        android:textSize="20sp" />

    <TextView
        android:id="@+id/textView9"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/textView8"
        android:textSize="20sp" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/textView9" …
Run Code Online (Sandbox Code Playgroud)

android textview android-layout android-imageview android-relativelayout

40
推荐指数
3
解决办法
6万
查看次数

以编程方式将ImageView的重力设置为android中心

我想用以下代码将Imageview数组的重力,ImageIcons [i]设置到中心,

ImageIcons[i] = new ImageView(this);
ImageIcons[i].setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
layout.addView(ImageIcons[i]);
Run Code Online (Sandbox Code Playgroud)

在设定引力时我被困住了.我要求SO人员指导我.

谢谢

android center dynamic gravity android-imageview

39
推荐指数
2
解决办法
6万
查看次数

使用ShapedDrawable将ColorFilter应用于ImageView

我有一个ImageViewandroid:src设置为一个ShapedDrawable,即白圈.我想要的是ImageView在响应某些事件的运行时将其着色.imgView.setColorFilter似乎是解决方案,但在使用此(尝试不同的参数)后,图像变得不可见(我在屏幕上看不到它).

怎么解决这个?还有更好的方法来制作彩色圆圈吗?

android drawable android-imageview colorfilter shapedrawable

39
推荐指数
3
解决办法
7万
查看次数

ImageView adjustViewBounds不起作用

我有一个ImageView android:layout_width=100dp,android:layout_height=wrap_contentandroid:adjustViewBounds=true

它的来源是50 x 50像素的图片.但不保留纵横比 - ImageView的高度为50px,而不是100px(即adjustViewBounds不工作).如果我有一个200x200px的图片它可以工作 - 宽度和高度是100px.此代码生成100px宽和50px高的图片,但src图像是正方形:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <ImageView
        android:id="@+id/photo"
        android:src="@drawable/icon"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:scaleType="fitXY"
        android:adjustViewBounds="true" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

android imageview android-imageview

38
推荐指数
2
解决办法
5万
查看次数

Android imageview更改色调以模拟按钮单击

我有一个imageview,我已经设置了一个从网址获取的位图.在imageview上,我设置了一个打开对话框的onClickListener.

当按下imageview时,我想以某种方式改变色调(使其变暗)以提供类似按钮的点击感觉.

你有什么建议?

android android-ui android-imageview

38
推荐指数
3
解决办法
2万
查看次数

在Android中以编程方式实现android:src ="@ drawable/image"

我试图在图像按钮上设置前景图像.经过一些研究,我发现了这个代码示例:

<ImageButton android:text="Button" android:id="@+id/button1"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:src="@drawable/icon"/>
Run Code Online (Sandbox Code Playgroud)

我的查询是如何在代码中实际实现android:src.

android android-widget android-imageview android-button

36
推荐指数
2
解决办法
7万
查看次数

将图像的字节数组转换为imageview

我搜索了一下但是无法清楚地看到它.如何将Image的字节数组设置为imageview?我BufferedImage img = ImageIO.read(new ByteArrayInputStream(bytes));在java中尝试了字符串,但不能:(任何人都可以帮助我吗?抱歉,如果问题就像一个菜鸟:)

android android-imageview

36
推荐指数
1
解决办法
6万
查看次数