基于父高度调整的ImageView [英] Resize Imageview based on the parent height
问题描述
我有一个版面下方
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="vertical" >
<ImageView
android:id="@+id/movieImageView"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_centerVertical="true"
android:paddingBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:src="@drawable/blank_96_1382x" />
<TextView
android:id="@+id/movieTypeView"
android:layout_width="75dp"
android:layout_height="wrap_content"
android:layout_below="@+id/movieImageView"
android:layout_alignLeft="@+id/movieImageView"
android:maxLines="1"
android:text="Tv Series"
android:textColor="@color/gray"
android:textSize="12sp"
android:gravity="center"
android:paddingTop="3dp"
android:paddingBottom="3dp"
android:visibility="gone"
android:textStyle="bold" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerVertical="true"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="@id/movieImageView"
android:layout_marginLeft="5dp">
<TextView
android:id="@+id/movieTitleView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="3"
android:text="Shutter Island starring leonardo di caprio"
android:textColor="@color/white"
android:textSize="17sp"
android:textStyle="bold"
android:typeface="sans" />
...
</RelativeLayout>
这应该是这样的
It would look like this
我希望的ImageView收缩基于关于imageview的左侧的内容。例如,如果几个字段缺失和田野的高度之和小于图像的高度就应该收缩(如下图所示)。
I want the imageview to shrink based on the contents on the left side of the imageview. For instance if few fields are missing and sum of heights of fields is less than image height then it should shrink (as shown below) .
如果图像对的左侧的字段的高度的总和大于规定的图像高度大于它应该保持为低于规定高度
If sum of heights of the fields on left side of image is greater than specified image height then it should retain the specified height as below
我试图扩大图像视图的ImageView和变化高度/宽度reatining图像的长宽比为这里<一个解释href=\"http://stackoverflow.com/questions/9914810/how-to-set-both-min-and-max-size-for-an-imageview-in-android\">custom图像视图。但问题是,由 MeasureSpec.getSize(heightMeasureSpec)返回父高度
不返回由字段左侧占领(因为这将仅onMeasure后可用的确切高度所有子返回)。因此,这种方法并没有把我的任何地方。
I tried extending imageview and change height/ width of image view reatining the aspect ratio of image as explained here custom image view. But problem is, parent height returned by MeasureSpec.getSize(heightMeasureSpec)
does not return the exact height occupied by fields on the left side (since that will be available only after onMeasure of all child is returned). So this approach did not take me anywhere.
我怎样才能达到这个期望的行为?
How can I achieve this desired behavior ?
推荐答案
试试这个...
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
>
<ImageView
android:id="@+id/ivOne"
android:src="@drawable/ic_launcher"
android:layout_width="90dp"
android:layout_height="90dp" // you can check by changing the values.
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:padding="5dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center|center_horizontal">
<EditText
android:id="@+id/etOne"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Text:"
android:textColorHint="#4584a1"
android:layout_margin="10dp"
android:textColor="#4584a1"
>
</EditText>
<EditText
android:id="@+id/etTwo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Text"
android:textColorHint="#4584a1"
android:layout_margin="10dp"
android:textColor="#4584a1"
>
</EditText>
</LinearLayout>
</LinearLayout>
我希望这会有所帮助。
I hope it will help.
这篇关于基于父高度调整的ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!