相关疑难解决方法(0)

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中的图像按钮上保持宽高比?

我有5个方形的ImageButtons,我想在屏幕的底部并排排列.我有每一组(不同的id):

        <ImageButton
         android:id="@+id/box1" 
         android:layout_width="fill_parent"
         android:layout_height="wrap_content" 
         android:layout_gravity="center"
         android:adjustViewBounds="true"
         android:scaleType="fitXY"
         android:layout_weight="1"
         android:layout_margin="1dp"
         /> 
Run Code Online (Sandbox Code Playgroud)

我在主java中分配了这样的背景:

    int[] imageIds = new int[] {R.id.box1,R.id.box2,R.id.box3,R.id.box4,R.id.box5};
    for(int i = 0; i<5; i++){
        imageButtons[i] = (ImageButton) findViewById(imageIds[i]);
        imageButtons[i].setBackgroundResource(R.drawable.blank);
    }
Run Code Online (Sandbox Code Playgroud)

我想要做的是缩放宽度以便在屏幕底部整齐地并排放置(现在可以正常使用),但是高度也会自动缩放以匹配宽度.这可能吗?我不想使用setImageSource,因为它在图像按钮周围放置了一个边框.

android aspect-ratio imagebutton

37
推荐指数
3
解决办法
4万
查看次数

android adjustViewBounds错误?

当我在我的imageView xml中使用android:adjustViewBounds ="true"时,它不起作用.如果我把setAdjustViewBounds(true); 在我的ImageView的构造函数中,它工作正常.有什么区别,或者这是一个错误?

<ImageView
                android:id="@+id/PageViewMainImage"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:scaleType="matrix"     
                android:adjustViewBounds="true"               
                android:visibility="invisible"/>
Run Code Online (Sandbox Code Playgroud)

android imageview

4
推荐指数
1
解决办法
9025
查看次数