android imageview into相对布局设置高度

时间:2017-02-27 07:56:17

标签: android android-layout android-imageview android-relativelayout

我有一个Relativelayout的图像视图,我从图库中选择图像..问题是Imageview高度太大,相对布局父高度与{{{ 1}}高度,我需要从图库中选择图像并将其精确地显示在这个相对布局中。

在我的代码下面

Imageview

3 个答案:

答案 0 :(得分:1)

试试这个:删除android:layout_alignParentEnd="true"

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">


    <ImageView
        android:id="@+id/image_view"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:layout_margin="5dp"
        android:adjustViewBounds="true"
        android:scaleType="fitXY"
        android:src="@drawable/calender" />
</RelativeLayout>

答案 1 :(得分:1)

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:src="@drawable/bgg"
    android:id="@+id/imageView8"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="71dp" />
</RelativeLayout>

答案 2 :(得分:1)

我也遇到了同样的问题:试试这个

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white">

    <ImageView
        android:id="@+id/flag"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentEnd="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="false"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:adjustViewBounds="true"
        android:background="@color/white"
        android:foregroundGravity="center"
        android:scaleType="fitXY"
        android:src="@drawable/guide3" />

</RelativeLayout>